开发者

Perceiving objects accessed/updated by DML in Oracle

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开发者_JAVA技巧 changed) is not an option.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜