I had created an Oracle PL/SQL package with a header and a body with lots of code. Later, I ended up accidentally erasing the code from that body after reran the CREATE OR REPLACE PACKAGE BODY... statement with different source code (which actually I intended to save under a different package name). Is there anyway I can recover my older replaced source code from the packege?
views:
339answers:
2
+3
A:
Unless you have logging/auditing of DDL commands enabled, or a backup of the database, then the answer is almost certainly not
Database definitions, including stored procedures, should always be treated like source code, and maintained in a code repository
Mark Baker
2010-06-04 18:20:36
Source control is a must on any and all code, including DB stuff. Small incremental changes and frequent check-ins is key to smooth software development for sure.
Brian T Hannan
2010-06-04 21:10:32
Thanks for your comments - unfortunately I learnt this the hard way. Actually I almost got around to saving a hard copy of the code using the "Export DDL" option in SQL Developer when I had finished - but something came up and I lost track of it. Anyway - this episode ensures I will not forget it again.
VVP
2010-06-04 23:14:57
It's happened to us all. There are only 2 types of people: those who do backups/use source control, and those who have never had a data loss
Mark Baker
2010-06-05 07:54:47
Source control comments aside, the answer is to use flashback as described by @carpenteri
Nick Pierpoint
2010-06-05 23:22:22
+4
A:
You might be able to get it back by using a flashback query on all_source.
e.g. my package body is currently at version 2, executing this query as a standard user:
SQL> select text
2 from all_source
3 where name = 'CARPENTERI_TEST'
4 and type = 'PACKAGE BODY';
TEXT
package body carpenteri_test
is
procedure do_stuff
is
begin
dbms_output.put_line('version 2');
end do_stuff;
end carpenteri_test;
10 rows selected.
I know I changed this around 9:30 this evening so after connecting as a SYSDBA user I ran this query:
SQL> select text
2 from all_source
3 as of timestamp
4 to_timestamp('04-JUN-2010 21:30:00', 'DD-MON-YYYY HH24:MI:SS')
5 where name = 'CARPENTERI_TEST'
6 and type = 'PACKAGE BODY';
TEXT
----------------------------------------------------------------------------
package body carpenteri_test
is
procedure do_stuff
is
begin
dbms_output.put_line('version 1');
end do_stuff;
end carpenteri_test;
10 rows selected.
More information on flashback can be found here. Tom Kyte also demostrates how to use flashback with all_source here.
carpenteri
2010-06-04 21:05:00
Thanks - I tried the first one (w/o the timestamp) and it gave me the latest code. Then I added the timestamp and got "insufficient privileges" error. Will forward it to the dba who can maybe do it for me.
VVP
2010-06-04 23:13:06
point your DBA to this link from Tom Kyte:http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:6135698985750#13932884772332
carpenteri
2010-06-07 18:51:12
Glad I could help. I've amended my answer to make it clear that you need to connect to as sys and included the link to Tom Kyte's example.
carpenteri
2010-06-08 07:03:35