If your tables have MONITORING
, one approach is to just use the data dictionary to see table modifications. Provided MONITORING
is on, the below approach should let you see what tables have received INSERT
s (or UPDATE
s or DELETE
s, if desired) over a given time period.
The below approach has the disadvantage that one must actually wait 10 minutes before checking what has been created, but it doesn't require tables to have any particular column.
Update: as per Ikrom's comment, the original answer was flawed by checking the data dictionary only once. This answer has been updated to check twice to detect changes.
This approach will record baseline table modification counts, then check back for any changes 10 minutes later. It uses two work-tables one for reference ALL_TAB_MODIFICATIONS_REF
and one to view the modified tables after 10 min ALL_TAB_MODIFICATIONS_COMPARE
:
CREATE GLOBAL TEMPORARY TABLE
ALL_TAB_MODIFICATIONS_REF
ON COMMIT PRESERVE ROWS
AS SELECT * FROM ALL_TAB_MODIFICATIONS WHERE ROWNUM < 0;
CREATE GLOBAL TEMPORARY TABLE
ALL_TAB_MODIFICATIONS_COMPARE
ON COMMIT PRESERVE ROWS
AS SELECT * FROM ALL_TAB_MODIFICATIONS WHERE ROWNUM < 0;
Table created.
Table created.
After creating these work tables, one can detect any changes by taking initial state and comparing to final state after 10 minutes. After running the below block, one can query ALL_TAB_MODIFICATIONS_COMPARE
to see what tables have been INSERT
ed.
BEGIN
--Flush monitoring info, to get a baseline.
DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO();
--Capture the initial state.
INSERT INTO ALL_TAB_MODIFICATIONS_REF
SELECT * FROM ALL_TAB_MODIFICATIONS;
COMMIT;
-- Wait ten minutes.
DBMS_LOCK.SLEEP(600);
--Flush monitoring info, to get a snapshot for comparison.
DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO();
-- Capture the final state.
INSERT INTO ALL_TAB_MODIFICATIONS_COMPARE
SELECT * FROM ALL_TAB_MODIFICATIONS
WHERE NOT EXISTS(SELECT 1 FROM ALL_TAB_MODIFICATIONS_REF
WHERE ALL_TAB_MODIFICATIONS_REF.TABLE_OWNER = ALL_TAB_MODIFICATIONS.TABLE_OWNER
AND ALL_TAB_MODIFICATIONS_REF.TABLE_NAME = ALL_TAB_MODIFICATIONS.TABLE_NAME
AND ALL_TAB_MODIFICATIONS_REF.INSERTS >= ALL_TAB_MODIFICATIONS.INSERTS);
COMMIT;
END;
/
After running the block, check for tables with INSERT
s:
SELECT TABLE_NAME FROM ALL_TAB_MODIFICATIONS_COMPARE;
Here's an example to detect changes to one table over 10 mins, but to exclude the other since it has been 10+ minutes since its last INSERT
:
Create test tables:
CREATE TABLE RECENT_DML (THE_DATA NUMBER, DML_TIME TIMESTAMP DEFAULT SYSTIMESTAMP NOT NULL);
CREATE TABLE NO_RECENT_DML (THE_DATA NUMBER, DML_TIME TIMESTAMP DEFAULT SYSTIMESTAMP NOT NULL);
Table created.
Table created.
And add some initial test-data in two tables.
INSERT INTO RECENT_DML (THE_DATA) VALUES (1);
INSERT INTO NO_RECENT_DML (THE_DATA) VALUES (1);
COMMIT;
1 row inserted.
1 row inserted.
Commit complete.
Then run the monitoring block above in one session above to detect changes after 10 minutes.
While the block is running in the first session, add more data in a second session to only RECENT_DML
.
INSERT INTO RECENT_DML (THE_DATA) VALUES (1);
COMMIT;
1 row inserted.
Commit complete.
After the block has completed in the first session, query for the modified tables:
SELECT TABLE_NAME FROM ALL_TAB_MODIFICATIONS_COMPARE;
TABLE_NAME
RECENT_DML