Mview Refresh error while doing Force refresh - oracle

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.

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.

Related

Create matview refresh fast on commit fails with ORA-12033

Oracle Database - Standard Edition - Version 12.1.0.2.0, platform Windows 64-bit
I'm getting ora-12033 error while trying to create mview, all necessary columns are already included in the mview log. When i'm trying to do same thing on 11g version it works, but 12c throwing ora error.
Please help me solve this problem or provide links that may help.
Here is code:
CREATE MATERIALIZED VIEW LOG ON contract_details
with rowid (count, contract_id) including new values;
CREATE MATERIALIZED VIEW m_contract_sum
refresh fast on commit
as
select d.contract_id as contract_id,
count(*) as count_grp,
count(d.count) as cnt_count,
sum(d.count) as sm_count
from contract_details d
group by d.contract_id;
Thanks in advance!
There might be a problem with extended stats, which are automatically created to gather stats on group of columns.
You can verify it by executing following query:
SELECT column_name, data_default, virtual_column, hidden_column
FROM dba_tab_cols
WHERE table_name = 'CONTRACT_DETAILS' AND hidden_column = 'YES';
If this is a case, you need to drop the stats (using dbms_stats.drop_extended_stats) before (re-)creating materialized view.
e.g.
BEGIN
dbms_stats.drop_extended_stats('master', 'contract_details', '(x, y)');
END;
/
Afterwards you probably would like to gather the stats again, by using
BEGIN
dbms_stats.create_extended_stats('master', 'contract_details', '(x, y)')
END;
/

Oracle CREATE spatial INDEX fails with "too many values"

When trying to create a spatial index on any SDO_GEOMETRY column (tried from multiple users, including SYS), Oracle fails with this statement:
Error at line 1
ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine
ORA-00913: too many values
ORA-06512: at "MDSYS.SDO_INDEX_METHOD_10I", line 10
The database is quite old and creating spatial indexes worked in the past (there are already existing ones that work). A sample of creating an index we used:
CREATE TABLE TEST_SPATIAL_INDEX (FID NUMBER, GEOM SDO_GEOMETRY);
INSERT INTO USER_SDO_GEOM_METADATA
VALUES ( 'TEST_SPATIAL_INDEX', 'GEOM',
MDSYS.SDO_DIM_ARRAY(
MDSYS.SDO_DIM_ELEMENT('X', 601000, 619000, 0.1),
MDSYS.SDO_DIM_ELEMENT('Y', 6116000, 6142000, 0.1),
MDSYS.SDO_DIM_ELEMENT('Z', -200, 200, 0.1)),
NULL);
COMMIT;
create index TEST_SPATIAL_INDEX_1 on TEST_SPATIAL_INDEX(GEOM) indextype is mdsys.spatial_index;
Running statement:
select * from registry$history;
returns:
25-02-2015 11:54:06.449000
APPLY SERVER
11.2.0.3 0
Patchset 11.2.0.2.0
PSU
We have two instances (SIDs) under one server (same ORACLE HOME for both) and the other one works. We can't find any visible difference in NLS parameters or Oracle version etc that would set them apart. Any ideas what might be wrong?
It can be caused by 3rd party backup software - "IBM Tivoli Storage Manager for Databases". There is versions where after online backup database is left in invalid state.
However after restarting oracle service indexes can be created, until backup breaks it again.

Create Materialized view which refresh records on daily

Currently the Materialized view which I had created using REFRESH ON DEMAND so in this case I need to refresh MV explicitly using below command:
BEGIN DBMS_MVIEW.REFRESH('MV_DATA'); END;
But now I need to refresh this MV on daily basis so could anyone please help to write this. I have seen that we can refresh this MV using writing explicit Job or using COMPLETE/FAST REFRESH statement in MV itself.
Thanks in advance!
You need to create the materialized view using START WITH and NEXT Clause
create materialized view <mview_name>
refresh on demand
start with sysdate next sysdate + 1
as select ............
So if you want to refresh mview daily, you need to keep it refresh on demand and set the next refresh time as sysdate + 1. You can set any interval although.
Once you do this the materialized view is created and a job is set in Oracle that will refresh mview every 24 hrs (sysdate + 1).
For more information on how to do that, follow this link
If you simply need a SQL query to simply refresh at 12 AM, then the below query would be enough.
CREATE MATERIALIZED VIEW MV_DATA
BUILD IMMEDIATE
REFRESH FAST START WITH (SYSDATE) NEXT (SYSDATE + 1) WITH ROWID
ON COMMIT
DISABLE QUERY REWRITE
AS SELECT * FROM <YOUR TABLE>
If you need to have it refreshed around 6 AM, then use the below script. You can see and additional logic as + 6 / 24. In case if you need to change to 4 AM, use the logic as + 4 / 24.
CREATE MATERIALIZED VIEW MV_DATA
BUILD IMMEDIATE
REFRESH FAST START WITH (SYSDATE) NEXT (SYSDATE + 1) + 6 / 24 WITH ROWID
ON COMMIT
DISABLE QUERY REWRITE
AS SELECT * FROM <YOUR TABLE>
I have edited Sarath's Script for it to run on specific time (i.e. 6AM).
CREATE MATERIALIZED VIEW MV_DATA
BUILD IMMEDIATE
REFRESH FAST START WITH (SYSDATE) NEXT (TRUNC(SYSDATE) + 1) + 6 / 24 WITH ROWID
ON COMMIT
DISABLE QUERY REWRITE
AS SELECT * FROM YOURTABLE
Refresh the mv every day at 1 AM
CREATE MATERIALIZED VIEW test1
BUILD IMMEDIATE
USING INDEX
REFRESH COMPLETE ON DEMAND START WITH sysdate+0 NEXT (trunc(sysdate)+1)+1/24
USING DEFAULT LOCAL ROLLBACK SEGMENT
USING ENFORCED CONSTRAINTS DISABLE QUERY REWRITE
"Your query"

Oracle 11gR2 MView refresh failing

Hi I have created 5 MViews for tables in Remote DB 2 days back in production environment. Out of that one Mview, at the time of creation it worked fine. But 2 days after(today) the MView's last refresh date is still showing the day before yesterday's date.
I checked on the DBA_JOBS:
LAST_DATE,NEXT_DATE,BROKEN,INTERVAL,FAILURES,WHAT
NULL,"23-JUL-13 01:00:00", N,"trunc(SYSDATE+1)+1/24",12,"dbms_refresh.refresh('"OCCSS_ENTMT_HK"."MV_SCI_STD_CODE_VALUE"');"
MView create statement:
CREATE MATERIALIZED VIEW MV_SCI_STD_CODE_VALUE BUILD IMMEDIATE USING INDEX REFRESH FORCE ON DEMAND START WITH SYSDATE+0 NEXT TRUNC(SYSDATE+1)+1/24 WITH PRIMARY KEY USING DEFAULT LOCAL ROLLBACK SEGMENT USING ENFORCED CONSTRAINTS DISABLE QUERY REWRITE AS SELECT STV_STD_CODE_NUM STANDARD_CODE,
STV_STD_CODE_VALUE STANDARD_CODE_VALUE,
STV_STD_CODE_VALUE_DESC DESCRIPTION,
stv_prnt_std_code_value parent_code FROM SCIADMIN.P03_STD_CODE_VALUE#SCI_LINK02.HK.BT.COM P03 WHERE STV_STD_CODE_NUM IN ('19','31','54','5','6','300') AND p03.update_status_ind <> 'D';
COMMENT ON MATERIALIZED VIEW MV_SCI_STD_CODE_VALUE IS 'snapshot table for snapshot MV_SCI_STD_CODE_VALUE';
The Mview is scheduled to run once in one day. But the failures shown is 12.
I couldn't find any jobs for the above in DBMS_JOBS_RUNNING.
I need to investigate this issue. What would be the possible issues which could have caused this failure?

Recovering deleted Records

I have accdently deleted some rows in a table and did the commit too. Now
I want to recover them.
The DB I'm using is Oracle 11g R2.
I used the following query to get deleted records:
SELECT * FROM MY_TABLE AS OF TIMESTAMP ('13-MAR-11 8:50:58','DD-MON-YY HH24: MI: SS')
But while executing it gives an error saying:
Error at Command Line:3 Column:75
Error report:
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
But I couldn't figure the problem in this queury.
Can anyone pls help?
That requires an actual timestamp (or date), you're passing a pair of values.
Try:
SELECT * FROM MY_TABLE
AS OF TIMESTAMP TO_DATE('13-MAR-11 08:50:58','DD-MON-YY HH24:MI:SS')
(Your time format specifier isn't correct either and doesn't match your date string.)
for example :
SELECT * FROM EMP AS OF TIMESTAMP
TO_TIMESTAMP('2005-04-04 09:30:00', 'YYYY-MM-DD HH:MI:SS')
WHERE name = 'JOHN';
But flashback query may fail with ORA-1555 , other option :
Logminer
if Oracle supplement log is enabled , you can get undo sql for your delete statement
-- switch again logfile to get a minimal redo activity alter system switch logfile;
-- mine the last written archived log
exec dbms_logmnr.add_logfile('archivelog/redologfile', options =>dbms_logmnr.new);
exec dbms_logmnr.start_logmnr(options => dbms_logmnr.dict_from_online_catalog);
select operation, sql_redo from v$logmnr_contents where seg_name = 'EMP';
Oracle PRM-DUL
PRM-DUL will be last option. Even deleted row piece in Oracle block is always just marked row flag with deleted mask, the row piece still can be read via scan Oracle data block . PRM-DUL can scan the whole table , find out every record/row piece marked deleted and write out to flat file.

Resources