OracleSCN_TO_TIMESTAMP函数的使用-成都快上网建站

OracleSCN_TO_TIMESTAMP函数的使用

该内容来源官网:

茂南网站制作公司哪家好,找创新互联建站!从网页设计、网站建设、微信开发、APP开发、响应式网站建设等网站项目制作,到程序开发,运营维护。创新互联建站从2013年成立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联建站

http://docs.oracle.com/cd/E11882_01/server.112/e41084/functions161.htm#BABEHBCB

 

其用法很简单

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_TIMESTAMP is 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

标题名称:OracleSCN_TO_TIMESTAMP函数的使用
本文路径:http://kswjz.com/article/iedssh.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流