oracle scntotimestamp,Oracle SCN_TO_TIMESTAMP函数的使用

该内容来源官网:

其用法很简单

scn_to_timestamp(number),其中number指的是系统当前生产的SCN

文档中NOTE部分提到一个内容值得注意:

The association between an SCN and a timestamp when the SCN is generated is remembered by the database for a limited period of time. This period is the maximum of the auto-tuned undo retention period, if the database runs in the Automatic Undo Management mode, and the retention times of all flashback archives in the database, but no less than 120 hours. The time for the association to become obsolete elapses only when the database is open. An error is returned if the SCN specified for the argument toSCN_TO_TIMESTAMPis too old.

这里说到当SCN生成时数据库在有限的期限内保留SCN和TIMESTAMP间的关系,这个期限是由undo最大的保存时间来确定,如果数据库运行了UNDO的自动管理,并且存储的闪回归档不小于120小时,则仅当数据库开启时这个关系会过期,当通过SCN_TO_TIMESTAMP函数查询时,会返回参数太旧的错误提示。

同时文档中提到一个有趣的用法,Oracle提供了一个叫ORA_ROWSCN的虚拟列,当你对某些表进行查询是,通过SCN_TO_NUMBER()参数中指定该虚拟字段,其返回的结果是该表中行最后一次升级的时间。

SQL> select scn_to_timestamp(ORA_ROWSCN) from tbilllog3;

SCN_TO_TIMESTAMP(ORA_ROWSCN)

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

05-JAN-15 02.25.28.000000000 PM

05-JAN-15 05.28.56.000000000 PM

其目的主要在于闪回查询,通过时间戳将数据回退到某一个时间点。例子可以看一下官网中的介绍

如果指定的是未来的某个SCN数,则会出现如下错误,

SQL> select scn_to_timestamp(2095591) from dual;

select scn_to_timestamp(2095591) from dual

*

ERROR at line 1:

ORA-08181: specified number is not a valid system change number

ORA-06512: at "SYS.SCN_TO_TIMESTAMP", line 1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值