替换为较新的代码后,是否可以从包主体中恢复较旧的 Oracle pl/sql 源代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2976682/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 02:37:15  来源:igfitidea点击:

Can I recover older Oracle pl/sql source code from a package body after i have replaced with newer code

oraclereplacepackagerecover

提问by VVP

I had created an Oracle PL/SQL package with a header and a body with lots of code.

我创建了一个 Oracle PL/SQL 包,其中包含一个标题和一个包含大量代码的正文。

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).

后来,在CREATE OR REPLACE PACKAGE BODY...使用不同的源代码(实际上我打算保存在不同的包名下)重新运行语句后,我最终不小心从该主体中删除了代码。

Is there any way I can recover my older replaced source code from the package?

有什么方法可以从包中恢复旧的替换源代码?

回答by Ian Carpenter

You might be able to get it back by using a flashback query on all_source.

您可以通过对 all_source 使用闪回查询来恢复它。

e.g. my package body is currently at version 2, executing this query as a standard user:

例如,我的包主体当前为版本 2,以标准用户身份执行此查询:

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:

我知道我在今晚 9:30 左右更改了此设置,因此在以 SYSDBA 用户身份连接后,我运行了以下查询:

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_sourcehere.

可以在此处找到有关闪回的更多信息。汤姆凯特还演示功能如何使用闪回与ALL_SOURCE这里

回答by Mark Baker

Unless you have logging/auditing of DDL commands enabled, or a backup of the database, then the answer is almost certainly not

除非您启用了 DDL 命令的日志记录/审计,或者数据库的备份,否则答案几乎肯定不是

Database definitions, including stored procedures, should always be treated like source code, and maintained in a code repository

数据库定义,包括存储过程,应始终像源代码一样对待,并在代码存储库中维护