Flashback Query(函数示例)

Flashback Query 函数,存储过程,包,触发器等对象
Flashback Drop 可以闪回与表相关联的对象, 如果是其他的对象,比如function,procedure,trigger等。 这时候,就需要使用到ALL_SOURCE 表来进行Flashback Query。
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.
基于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
2 as
3 v_date date;
4 begin
5 select sysdate into v_date from dual;
6 return v_date;
7 end;
8 /

函数已创建。

---------------查询函数---------------------------------------

SQL> ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS';

会话已更改。

SQL> select getdate() from dual;

GETDATE()
-------------------
2014-10-16 21:52:11

------------查询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行。

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

SQL> drop function getdate;

函数已删除。

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

未选定行

--------------------使用flashback query 查询-------------------------------------

SQL> select text from dba_source as of timestamp to_timestamp('2014-10-16 21:52:11','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行。

重新执行该函数的代码即可恢复getdate函数

《FROM:http://blog.csdn.net/tianlesoftware/article/details/4677378

posted on 2014-10-16 22:04  遠離塵世の方舟  阅读(228)  评论(0编辑  收藏  举报

导航