Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to query the changes made by a materialized view fast refresh in Oracle?

Say that you have two Oracle databases, DB_A and DB_B. There is a table named TAB1 in DB_A with a materialized view log, and a materialized view named SNAP_TAB1 in DB_B created with

CREATE SNAPSHOT SNAP_TAB1
REFRESH FAST
AS SELECT * FROM TAB1@DB_A;

Is there a way to query in DB_B the changes made to SNAP_TAB1 after each call to fast-refresh the materialized view ?

DBMS_SNAPSHOT.REFRESH( 'SNAP_TAB1', 'F' );

In DB_A, prior to the refresh, you can query the materialized view log table, MLOG$_TAB1, to see which rows have been changed in TAB1. I'm looking for a way to query in DB_B, after each refresh, which rows have been refreshed in SNAP_TAB1.

Thanks!

like image 474
Aurelio Martin Massoni Avatar asked Nov 14 '22 11:11

Aurelio Martin Massoni


1 Answers

I think the lines below work with prebuilt table:

You can add a column in the table SNAP_TAB1.

For inserts You can put it on default sysdate => for every insert you'll have the timestamp of the insert.

For updates you can use a trigger. Because the column is not involved in the Materialized View, updating the column with the trigger won't be a problem.

Probaly better, with the trigger you can use an unique id to store in that column, incremented before every new refresh.(Obtaining the unique id may have different aproaches.)

Obviously, you can't track deletes with this idea.

like image 68
Florin stands with Ukraine Avatar answered Dec 10 '22 05:12

Florin stands with Ukraine