Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question.

Asked: October 17, 2002 - 9:37 am UTC

Last updated: December 10, 2003 - 3:45 pm UTC

Version: 8.1.7.4

Viewed 1000+ times

You Asked

How do I get the following information from system tables -how do I
a)identify the DDL actions performed in last 24 hrs. If a developer overwrites some function, is there any way to get the old code from system tables?
b)identify the dependent objects and get the list of other objects dependent on the object in all schemas?
Thanks
Dilip

and Tom said...

a) auditing, you want to enable auditing.

No, once they overwrite the code -- the old code is gone, wiped out, not there anymore.


Interesting idea I just had tho -- you could use a DDL trigger (before create) to maybe capture the code and do the audit as well?

ops$tkyte@ORA817DEV.US.ORACLE.COM> create table old_code
2 as
3 select user username, 0 version, sysdate date_changed, user_source.*
4 from user_source
5 where 1=0
6 /

Table created.

ops$tkyte@ORA817DEV.US.ORACLE.COM> create sequence version_seq;

Sequence created.

ops$tkyte@ORA817DEV.US.ORACLE.COM>
ops$tkyte@ORA817DEV.US.ORACLE.COM>
ops$tkyte@ORA817DEV.US.ORACLE.COM> create or replace trigger create_trigger
2 before create on schema
3 declare
4 l_date date := sysdate;
5 l_ver number;
6 begin
7 if (ora_dict_obj_type in ( 'PACKAGE', 'PACKAGE BODY', 'PROCEDURE', 'FUNCTION' ) )
8 then
9 select version_seq.nextval into l_ver from dual;
10
11 insert into old_code
12 select user, l_ver, l_date, user_source.*
13 from user_source
14 where name = ora_dict_obj_name
15 and type = ora_dict_obj_type;
16 end if;
17 end;
18 /

Trigger created.

ops$tkyte@ORA817DEV.US.ORACLE.COM>
ops$tkyte@ORA817DEV.US.ORACLE.COM> create or replace function f return number
2 as
3 begin
4 return 0;
5 end;
6 /

Function created.

ops$tkyte@ORA817DEV.US.ORACLE.COM> select * from old_code;

no rows selected

ops$tkyte@ORA817DEV.US.ORACLE.COM> create or replace function f return date
2 as
3 begin
4 return sysdate;
5 end;
6 /

Function created.

ops$tkyte@ORA817DEV.US.ORACLE.COM> select * from old_code;

USERNAME VERSION DATE_CHAN NAME TYPE LINE TEXT
---------- ------- --------- ---- -------- ---- -------------------------
OPS$TKYTE 2 17-OCT-02 F FUNCTION 1 function f return number
OPS$TKYTE 2 17-OCT-02 F FUNCTION 2 as
OPS$TKYTE 2 17-OCT-02 F FUNCTION 3 begin
OPS$TKYTE 2 17-OCT-02 F FUNCTION 4 return 0;
OPS$TKYTE 2 17-OCT-02 F FUNCTION 5 end;

ops$tkyte@ORA817DEV.US.ORACLE.COM>





b) DBA_DEPENDENCIES has that information.

Rating

  (7 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Dilip Majithia, October 17, 2002 - 4:46 pm UTC

That's what I was looking for!
Thanks

Dave, October 17, 2002 - 11:12 pm UTC

Now THAT is going straight onto all of my databases! What a great bit of work, thanks a lot.

Bhagat Singh, October 17, 2002 - 11:45 pm UTC

May be it may look bit of work but actually till the problem is not solved it is big it is really very good/usefull sample of code given by Tom. I really appreciate his efforts they are commendable.

Sagi, October 18, 2002 - 5:51 am UTC

Hi Tom,

Simply superb.

Regards.

Great work

Vijay'S, October 18, 2002 - 8:41 am UTC

Simply great all of things you tell Tom are worth reading and implementing

source text in one row?

Susan, December 10, 2003 - 10:50 am UTC

Tom,

Could you recommend an approach for storing the old_code text in one row for a given object instead of a row per line of code. Thanks for any suggestions.

Tom Kyte
December 10, 2003 - 3:45 pm UTC

guess I'd ask "why" since if you restore it, you'd want it in seperate lines so you can use the array interface with dbms_sql to parse it.

but, sure, you can use a clob, insert an empty_clob() and "return it", and then use dbms_lob.writeAppend to the clob each of the lines

A reader, May 02, 2014 - 9:17 pm UTC

Tom How much is your salary and bonus? Is it 200K ?

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library