Skip to Main Content
  • Questions
  • Question on materialized view when concatenating several columns as a new column - cannot REFRESH FAST ON COMMIT

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Charlie.

Asked: May 08, 2017 - 9:55 am UTC

Last updated: July 12, 2021 - 5:28 pm UTC

Version: Oracle 10.1.2

Viewed 1000+ times

You Asked

There is an error when my view is when concatenating several columns as a new column, it cannot REFRESH FAST ON COMMIT.


CREATE MATERIALIZED VIEW LOG ON EXP_DC_HST
WITH SEQUENCE, ROWID
(ACTIVITY_DESCRIPTION, ACTIVITY_TYPE, CD1, CD2, CD3, CD4, Capture_date)
INCLUDING NEW VALUES;

and with the Materialized view

CREATE MATERIALIZED VIEW EXP_DC_AMEND_MVIEW
PARALLEL
BUILD IMMEDIATE
REFRESH FAST ON COMMIT AS
select H.ACTIVITY_TYPE, H.CD1|| H.CD2|| trim(H.CD3)||'-'||LPAD(H.CD4,2,0) as EXP_DC_NUMBER, max(H.Capture_date) as DC_STATUS_TIME
from EXP_DC_HST H where H.ACTIVITY_TYPE = 'AMENDMENT'
AND INSTR(H.ACTIVITY_DESCRIPTION, 'INFORMAL') = 0
group by H.ACTIVITY_TYPE, H.CD1, H.CD2, H.CD3, H.CD4;

It only works when the select is CD1, CD2, CD3, CD4 but not H.CD1|| H.CD2|| trim(H.CD3)||'-'||LPAD(H.CD4,2,0)

and Connor said...

There are limits to how far we can "probe" to make sure we can fast refresh. Once you get into expressions and functions, then generally you are going to have issues because we'd need to probe *into* every function to make sure that are safe etc.

Easy work around though.

1) create your materialized view with the 4 columns separate
2) create a normal view on top of it with the concatenation

Rating

  (4 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Charlie Siu, May 09, 2017 - 3:09 am UTC


It can created after adding those 4 columns but it does not refresh on commit

Charlie Siu, May 09, 2017 - 3:11 am UTC

When i try to insert / update the column on the underlying table (update the columns that is in the materialized view log).

the materialized view did not refresh...do i missing something?

More info to provide

Charlie Siu, May 09, 2017 - 3:31 am UTC

CREATE MATERIALIZED VIEW LOG ON EXP_DC_HST
WITH SEQUENCE, ROWID
(ACTIVITY_DESCRIPTION, ACTIVITY_TYPE, CD1, CD2, CD3, CD4, Capture_date)
INCLUDING NEW VALUES;

CREATE MATERIALIZED VIEW EXP_DC_AMEND_MVIEW
PARALLEL
BUILD IMMEDIATE
REFRESH FAST ON COMMIT AS
select H.ACTIVITY_DESCRIPTION, H.ACTIVITY_TYPE, H.CD1, H.CD2, H.CD3, H.CD4, H.CD1|| H.CD2|| trim(H.CD3)||'-'||LPAD(H.CD4,2,0) as EXP_DC_NUMBER,
max(H.Capture_date) as DC_STATUS_TIME
from EXP_DC_HST H where H.ACTIVITY_TYPE = 'AMENDMENT'
AND INSTR(H.ACTIVITY_DESCRIPTION, 'INFORMAL') = 0
group by H.ACTIVITY_DESCRIPTION, H.ACTIVITY_TYPE, H.CD1, H.CD2, H.CD3, H.CD4;

when i tried to insert a new record in EXP_DC_HST and commit, the MVIEW did not refresh..
Connor McDonald
May 15, 2017 - 7:56 pm UTC

Can we have a *full* test case please.

source table + sample data

So we can run your mview statements

mathguy, July 12, 2021 - 3:19 pm UTC

Concatenation,
TRIM
etc. have nothing to do with fast refresh of mv's; they don't cause any trouble. The issue in this problem is that the OP aggregates over
capture_date
. For the mv to be fast refreshable, the
SELECT
list must include
count(capture_date)
, and the OP's
SELECT
list does not.

It is trivial to build a fast refreshable mv over
SCOTT.EMP
to prove this. (Both that "concatenation and
TRIM
and such are no obstacle" and that the issue is the missing
COUNT()
in the
SELECT
list.)
Chris Saxon
July 12, 2021 - 5:28 pm UTC

Good points