We have 4 Mviews which uses Force refresh method to get refreshed every day using our control-M jobs after loading new data in the base table (The Mview logs created on the base tables). In our Current Production DB (11g), Non-Production it is working fine and these is issue while refreshing these views. Now we are moving our DB to oracle 12c and as part of migration we are importing all the objects from current 11g to new 12c DB.
So now when we run our control-M jobs to load new data in base tables and after that force refresh these mviews they got failed with ORA-12008: error in materialized view refresh path ORA-00923: FROM keyword not found where expected
I tried running the query used in Mview and they work fine(on new 12c DB) as excepted and did not give any error I tried gather stat and tried refreshing after that but still error persist to refresh, we tried dropping the MVIEWS and Recreating them as well but same error persist, use CTAS with MVIEW select query and table got created without error with data in it.
Below are supporting DDL of one of the Mview --
CREATE MATERIALIZED VIEW HEW.MV_EUC_MVT_ADM_MULTI
(NUMCOM,ACCOUNT,BANK_CODE,PRODUCT,CUST_TYPE,
SOURCE,CI,DEVISE,"DATE TRT",DATE_CBL,
ORIGINE,MONTANT,MONTANT_CVEUR,SENS,ENTITE,
AFFILIATE,BOOK_CODE,BU,MAFF,J_SOURCE,
PM)
NOCACHE
LOGGING
NOCOMPRESS
BUILD IMMEDIATE
REFRESH FORCE ON DEMAND
WITH PRIMARY KEY
AS
/* Formatted on 7/5/2021 1:03:02 PM (QP5 v5.277) */
SELECT SUBSTR ('00000000000' || MVT.ACCOUNT,
LENGTH ('00000000000' || MVT.ACCOUNT) - 10,
11)
|| SUBSTR ('000000' || MVT.PRODUCT,
LENGTH ('000000' || MVT.PRODUCT) - 5,
6)
|| SUBSTR ('0000000000' || MVT.CHARTFIELD2,
LENGTH ('0000000000' || MVT.CHARTFIELD2) - 9,
10)
|| SUBSTR ('0000000000' || MVT.CHARTFIELD1,
LENGTH ('0000000000' || MVT.CHARTFIELD1) - 9,
10)
AS NUMCOM,
MVT.ACCOUNT,
MVT.BANK_CODE AS BANK_CODE,
NVL (MVT.PRODUCT, '0') AS PRODUCT,
NVL (MVT.CHARTFIELD2, '0') AS CUST_TYPE,
NVL (MVT.CHARTFIELD1, '0') AS SOURCE,
SUBSTR (MVT.DEPTID, 6, 5) AS CI,
MVT.FOREIGN_CURRENCY AS DEVISE --,MVT.Z_DT_TRT AS DATE_TRT
,
MVT.DATE_SITU AS "DATE TRT",
MVT.JOURNAL_DATE AS DATE_CBL,
MVT.Z_CD_ORIGINE AS ORIGINE,
MVT.FOREIGN_AMOUNT AS MONTANT,
MVT.MONETARY_AMOUNT AS MONTANT_CVEUR,
DECODE (SIGN (MVT.FOREIGN_AMOUNT), 1, 'C', 'D') AS SENS,
SUBSTR (MVT.DEPTID, 8, 3) AS ENTITE,
NVL (MVT.AFFILIATE, '00000') AS AFFILIATE,
MVT.BOOK_CODE AS BOOK_CODE,
MVT.BUSINESS_UNIT_GL AS BU,
MVT.FISCAL_YEAR
|| TO_CHAR (TO_DATE (MVT.ACCOUNTING_PERIOD, 'MM'), 'MM')
AS MAFF,
MVT.SOURCE AS J_SOURCE,
DBMS_MVIEW.pmarker (mvt.ROWID) AS pm
FROM CRAFT_MVT_MULTI_H MVT, CRAFT_PARAM_DATE DT
WHERE ( ( MVT.FISCAL_YEAR = DT.fiscyear_lastday_mon_1
AND ACCOUNTING_PERIOD = DT.accper_lastday_mon_1)
OR ( MVT.FISCAL_YEAR = DT.fiscyear_yesterday
AND ACCOUNTING_PERIOD = DT.accper_yesterday))
AND ( ( (MVT.ACCOUNT LIKE '4%' OR MVT.ACCOUNT LIKE '5%')
AND MVT.FOREIGN_CURRENCY <> 'EUR'
AND (MVT.Z_CD_ORIGINE <> '716' OR MVT.Z_CD_ORIGINE IS NULL))
OR (MVT.ACCOUNT = '4083513001' AND MVT.FOREIGN_CURRENCY = 'EUR')
OR (MVT.ACCOUNT = '2059630001'))
AND MVT.DATE_SITU > DT.lastday_month_2;
CREATE MATERIALIZED VIEW LOG ON HEW.CRAFT_MVT_MULTI_H
NOCACHE
LOGGING
WITH ROWID
EXCLUDING NEW VALUES;
CREATE MATERIALIZED VIEW LOG ON HEW.CRAFT_PARAM_DATE
NOCACHE
LOGGING
WITH ROWID
EXCLUDING NEW VALUES;
Error --
ORA-12008: error in materialized view refresh path
ORA-00923: FROM keyword not found where expected
Detailed Error Message :
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2821
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 3058
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 3017
Please note that this Mview is getting force refreshed daily without error on our current 11g DB. Also one thing that I have noticed that just after the migration we run a DROP, Create script for all Mviews with Grants and all other things and after that when i do a force refresh on these Mview then they got refreshed but next day when we load new data in the base table and refresh these mviews only then they start throwing error so here i am assuming that the it gives error when we insert data in base tables !!
New 12c DB version --
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
Current working 11g DB version --
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
Please let me know you need more information I will try to arrange it.
1 Answer
Oracle does not use the query in the MVIEW definition to perform the refresh. It builds the refresh query dynamically using its own internal rules to leverage MVIEW Logs and other database features. There is a syntax error in the constructed refresh query, indicated by the ORA-00923 error: that is why you are able to initially create the MVIEW but refreshes are failing.
This is not something that you can correct directly. The recommended course of action as given in the Master Note for MVIEW 'ORA-' error diagnosis. For Materialized View CREATE or REFRESH is to open a Service Request with Oracle Support.