在用新代码替换后,我可以从包体中恢复旧的 Oracle pl/sql 源代码吗

发布于 2024-09-04 20:28:35 字数 189 浏览 15 评论 0原文

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

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

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

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 any way I can recover my older replaced source code from the package?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月牙弯弯 2024-09-11 20:28:35

您也许可以通过对 all_source 使用闪回查询来取回它。

例如,我的包主体当前处于版本 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.

我知道我在今晚 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.

可以找到有关闪回的更多信息 此处。 Tom Kyte 还演示了如何使用 all_source 闪回此处

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.

不乱于心 2024-09-11 20:28:35

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

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

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

昔日梦未散 2024-09-11 20:28:35

闪回查询不适用于 all_source 视图,您需要在 sys.source$ 上执行闪回查询,如下所示:

select source
    from sys.source$
    as of timestamp
    to_timestamp('8-NOV-2023 12:15:00', 'DD-MON-YYYY HH24:MI:SS')
where obj# = 109026;

Flashback query doesn't work on all_source view, you need to execute a flashback query on sys.source$ like this:

select source
    from sys.source$
    as of timestamp
    to_timestamp('8-NOV-2023 12:15:00', 'DD-MON-YYYY HH24:MI:SS')
where obj# = 109026;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文