如何从替换过程(PL / SQL)获取旧代码?

时间:2018-11-21 22:12:19

标签: oracle stored-procedures plsql

我有一个可以正常工作的程序,直到我错误地将其替换为其他代码。 因此,我的过程从CREATE OR REPLACE PROCEDURE xxx.yyy开始,然后我错误地替换了一些简单的代码并保存了它。

由于我在程序中进行了替换,因此它被替换了,但是现在它不再以我想要的方式工作。如何获得该过程中的旧代码(在替换之前)?

2 个答案:

答案 0 :(得分:2)

xxx模式连接时,请尝试使用:

select s.text 
  from user_source 
  as of timestamp systimestamp - interval '1' day s
 where s.name = 'YYY';

获取过程源。它为您提供前一天的数据。如果您的'1' day数据库参数已设置得足够大,则可以根据需要将'10' hour转换为'150' minutedb_flashback_retention_target等。 em>

答案 1 :(得分:0)

在搜索期间是否有存档日志。您可以使用实用程序LogMiner。 例如:

   CREATE OR REPLACE PACKAGE BODY acs_ss2.rest_of_day is

    /*------------------------------------------------------------------*/
    procedure starting(p_date date) is
      rec_newrest   r_rest%rowtype;
      rec_oldrest   r_rest%rowtype;
      rec_rest      r_rest%rowtype;
      v_station   integer := 8902;
      v_dt1 date;
      v_dt2 date;
    begin
SQL CODE...

在事件发生时确定所需的日志文件。

select name, first_time,  next_time
  from v$archived_log
where first_time >sysdate -3/24

/oracle/app/oracle/product/11.2/redolog/edcu/1_47429_769799469.dbf  22-ноя-2018 10:56:12    22-ноя-2018 12:13:48
/oracle/app/oracle/product/11.2/redolog/edcu/1_47430_769799469.dbf  22-ноя-2018 12:13:48    22-ноя-2018 13:17:06
/oracle/app/oracle/product/11.2/redolog/edcu/1_47431_769799469.dbf  22-ноя-2018 13:17:06    22-ноя-2018 13:39:38

运行logminer实用程序。

EXECUTE DBMS_LOGMNR.add_logfile(LOGFILENAME => '/oracle/app/oracle/product/11.2/redolog/edcu/1_47429_769799469.dbf', OPTIONS => DBMS_LOGMNR.NEW); 
EXECUTE DBMS_LOGMNR.add_logfile(LOGFILENAME => '/oracle/app/oracle/product/11.2/redolog/edcu/1_47430_769799469.dbf', OPTIONS => DBMS_LOGMNR.addfile); 
EXECUTE DBMS_LOGMNR.add_logfile(LOGFILENAME => '/oracle/app/oracle/product/11.2/redolog/edcu/1_47431_769799469.dbf', OPTIONS => DBMS_LOGMNR.addfile); 

EXECUTE DBMS_LOGMNR.START_LOGMNR(OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG);

运行SQL以恢复我们的CODE,请参见sql_undo列。

SELECT 
to_char(timestamp,'DD-MM-YYYY HH24:MI:SS'),
operation,  
sql_redo,
sql_undo
 FROM v$logmnr_contents
where 
seg_owner='SYS' and  
seg_name='SOURCE$'
==>
TO_CHAR(TIMESTAMP,'DD-MM-YYYYHH24:MI:SS')       OPERATION                              SQL_REDO                                                                                             SQL_UNDO                                                                                             
----------------------------------------------- -------------------------------------- ---------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------- 
22-11-2018 13:39:14                             DELETE                                 delete from "SYS"."SOURCE$" where "OBJ#" = '197353' and "LINE" = '1' and "SOURCE" = 'package body re insert into "SYS"."SOURCE$"("OBJ#","LINE","SOURCE") values ('197353','1','package body rest_of_day i 
22-11-2018 13:39:14                             DELETE                                 delete from "SYS"."SOURCE$" where "OBJ#" = '197353' and "LINE" = '2' and "SOURCE" = '
' and ROWID =  insert into "SYS"."SOURCE$"("OBJ#","LINE","SOURCE") values ('197353','2','
');                       
22-11-2018 13:39:14                             DELETE                                 delete from "SYS"."SOURCE$" where "OBJ#" = '197353' and "LINE" = '3' and "SOURCE" = '/*------------- insert into "SYS"."SOURCE$"("OBJ#","LINE","SOURCE") values ('197353','3','/*------------------------ 
22-11-2018 13:39:14                             DELETE                                 delete from "SYS"."SOURCE$" where "OBJ#" = '197353' and "LINE" = '4' and "SOURCE" = 'procedure start insert into "SYS"."SOURCE$"("OBJ#","LINE","SOURCE") values ('197353','4','procedure starting(p_date  
22-11-2018 13:39:14                             DELETE                                 delete from "SYS"."SOURCE$" where "OBJ#" = '197353' and "LINE" = '5' and "SOURCE" = '  rec_newrest r insert into "SYS"."SOURCE$"("OBJ#","LINE","SOURCE") values ('197353','5','  rec_newrest r_rest%rowty