Oracle procedure,package,function,triger 的Flashback Query

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

Oracle Flashback 技术 总结

http://blog.youkuaiyun.com/tianlesoftware/archive/2009/10/15/4677378.aspx

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

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

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

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

Related Views

DBA_SOURCE describes the text source of all stored objects in the database.

USER_SOURCE describes 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

Name Null? Type

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

OWNER VARCHAR2(30)

NAME VARCHAR2(30)

TYPE VARCHAR2(12)

LINE NUMBER

TEXT VARCHAR2(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

select sysdate 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

select sysdate 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

select sysdate into v_date from dual;

return v_date;

end;

7 rows selected.

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

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

Blog http://blog.youkuaiyun.com/tianlesoftware

Email: dvd.dba@gmail.com

DBA1 群:62697716(); DBA2 群:62697977() DBA3 群:62697850()

DBA 超级群:63306533(); DBA4 群: 83829929 DBA5群: 142216823

聊天 群:40132017 聊天2群:69087192

--加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值