Oracle procedure,package,function,triger 的Flashback Query

本文总结了Oracle Flashback技术,重点介绍了如何通过ALL_SOURCE表恢复误删除的对象,如函数、过程、触发器等。详细展示了从创建、查询、删除对象到使用FlashbackQuery恢复对象的过程,并提供了具体SQL示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

之前对Flashback进行了一个总结,参考:

Oracle Flashback技术总结

http://blog.youkuaiyun.com/xujinyang/article/details/6830438

在这篇文章里面,Flashback Query示例中只提到了对Table的Flashback Query。

如果是其他的对象,比如function,procedure,trigger等。这时候,就需要使用到ALL_SOURCE表。

先看联机文档对该表的说明:

ALL_SOURCE describes the text source of the stored objects accessible to the current user.

Related Views

DBA_SOURCEdescribes the text source of all stored objects in the database.

USER_SOURCEdescribes the text source of the stored objects owned by the current user. This view does not display the OWNER column.

Column

Datatype

NULL

Description

OWNER

VARCHAR2(30)

NOT NULL

Owner of the object

NAME

VARCHAR2(30)

NOT NULL

Name of the object

TYPE

VARCHAR2(12)

Type of object: FUNCTION, JAVA SOURCE, PACKAGE, PACKAGE BODY, PROCEDURE, TRIGGER, TYPE, TYPE BODY

LINE

NUMBER

NOT NULL

Line number of this line of source

TEXT

VARCHAR2(4000)

Text source of the stored object

如果我们误删除了某些对象,如procedure,就可以使用all_source表进行恢复。

SQL> desc dba_source

NameNull?Type

----------------------------------------- -------- ----------------------------

OWNERVARCHAR2(30)

NAMEVARCHAR2(30)

TYPEVARCHAR2(12)

LINENUMBER

TEXTVARCHAR2(4000)

查看dba_source的所有type

SQL> select type from dba_source group by type;

TYPE

------------

PROCEDURE

PACKAGE

PACKAGE BODY

TYPE BODY

TRIGGER

FUNCTION

TYPE

7 rows selected.

基于timestamp恢复的语句

SQL>SELECT text

FROM dba_source

AS OF TIMESTAMP TO_TIMESTAMP ('XXXXX', 'YYYY-MM-DD HH24:MI:SS')

WHERE owner = 'XXXX' AND name = '你删除的对象名'

ORDER BY line;

示例:

创建函数:

SQL> CREATE OR REPLACE function getdate return date

as

v_date date;

begin

selectsysdate into v_date from dual;

return v_date;

end;

/

Function created.

查询函数:

SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';

Session altered.

SQL> select getdate() from dual;

GETDATE()

-------------------

2011-04-07 21:02:09

查询dba_source表:

SQL> select text from dba_source where name='GETDATE' order by line;

TEXT

--------------------------------------------------------------------------------

function getdate return date

as

v_date date;

begin

selectsysdate into v_date from dual;

return v_date;

end;

7 rows selected.

drop函数,在查询,记录不存在

SQL> drop function getdate;

Function dropped.

SQL>select text from dba_source where name='GETDATE' order by line;

no rows selected

使用我们的Flashback Query查询:

SQL> select text from dba_source as of timestamp to_timestamp('2011-04-07 21:02:09','yyyy-mm-dd hh24:mi:ss') where name='GETDATE' order by line;

TEXT

--------------------------------------------------------------------------------

function getdate return date

as

v_date date;

begin

selectsysdate into v_date from dual;

return v_date;

end;

7 rows selected.

这时候,又查看到了函数的代码,只需要把这些代码重新执行一下就ok了。其他对象和这个类似。这里就不演示了。

-------------------------------------------------------------------------------------------------------

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值