I'm implementing the dependency system for changes in our DB, so eg for this and this change we need that and that object in such and such state. With DDL dependencies it's easy, but i need to know, what objects are referenced by the given DML clause. And the latter can be dynamic too.

So the question is: is there a way to say, what tables are referenced by the given DML code?

Primarily i'm interested in the clauses that don't modify table right away on my set of data but possibly shall modify it on client's side, because i cannot possibly have all the variations. So the indirect way of understanding (like executing a DML and then checking what tables have been changed) is not an option.

有帮助吗?

解决方案 2

I've investigated further and have found:

  1. Database change notifications don't work (SURPRISE!) on clauses that don't modify anything in the current state of data.

  2. But I think i'll finally use AUDIT/FGA. As of now it appears to understand clauses, that don't really change anything, works well with both explicit and dynamic DML in PL/SQL blocks and provides object_name - that's exactly what i need.

其他提示

if the DML code is a query, you could explain it and then check the PLAN_TABLE or dbms_xplan.display_cursor to check which objects are referenced by the query.

SQL> delete from plan_table;

4 rows deleted

SQL> explain plan for select * from scott.emp;

Explained

SQL> select * from table(dbms_xplan.display);

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 2872589290
--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |    14 |   518 |     2   (0)| 00:00:01 |
|   1 |  TABLE ACCESS FULL| EMP  |    14 |   518 |     2   (0)| 00:00:01 |
--------------------------------------------------------------------------

8 rows selected

SQL> SELECT operation, object_owner, object_name FROM plan_table;

OPERATION            OBJECT_OWNER       OBJECT_NAME
-------------------- ------------------ --------------------
SELECT STATEMENT                        
TABLE ACCESS         SCOTT              EMP

Obviously this would need that the query is valid in the database (all referenced objects already exist, etc...). If the code to be analyzed is a PL/SQL block, I don't see how you could do it short of writing a DIY parser.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top