Pages

Monday, March 4, 2024

ORA-12034: materialized view log on "SCHEMA"."MY_SERVICE" younger than last refresh

Issue: Refresh Materialized View is giving this error:

ERROR at line 1:
ORA-12034: materialized view log on "SCHEMA"."MY_MVIEW" younger than last refresh
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 794
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 851
ORA-06512: at "SYS.DBMS_IREFRESH", line 683
ORA-06512: at "SYS.DBMS_REFRESH", line 195
ORA-06512: at "SCHEMA.REFRESH_PKG", line 19
ORA-06512: at line 2

Solution:
Complete refresh and then Fast Refresh the Materialized View

Example
BEGIN
 DBMS_MVIEW.refresh('MY_MVIEW' ,'C');
END;
/
BEGIN
 DBMS_MVIEW.refresh('MY_MVIEW' ,'F');
END;
/

Code Generator
-----------------------------------------
--Generate DBMS_REFRESH.refresh script
-----------------------------------------
COLUMN sql_cmd FORMAT A120 WORD_WRAP
SET LINESIZE 120
SET PAGESIZE 0
SET HEADING OFF
SET FEEDBACK OFF
SET NEWPAGE NONE
SET VERIFY OFF
SET ECHO OFF
SET SHOW OFF
SET TERMOUT OFF

-----------------------------------------
--Generate DBMS_REFRESH.refresh script
-----------------------------------------
COLUMN sql_cmd FORMAT A120 WORD_WRAP
SET LINESIZE 120
SET PAGESIZE 0
SET HEADING OFF
SET FEEDBACK OFF
SET NEWPAGE NONE
SET ECHO OFF
SET TERMOUT OFF

spool manual_refresh_mviews.sql 
PROMPT SET FEEDBACK ON
SELECT 'spool refresh_'||name||'.log;'||CHR(10)||
'PROMPT Start DBMS_MVIEW.refresh() of '||name||CHR(10)||
'BEGIN'||CHR(10)||
' DBMS_MVIEW.refresh('''||name||''' ,''C'');' ||CHR(10)||
' DBMS_MVIEW.refresh('''||name||''' ,''F'');' ||CHR(10)||
' COMMIT;'||CHR(10)||
'END;'||CHR(10)||
'/'||CHR(10)||
'spool off;' as sql_cmd
FROM DBA_REFRESH_CHILDREN
WHERE rname = 'MASTER_GROUP'
order by name;
PROMPT spool off
spool off;

@manual_refresh_mviews.sql


No comments:

Post a Comment