您的位置:首页技术文章
文章详情页

Oracle 10g中SCN与TimeStamp的斗转星移

浏览:155日期:2023-11-28 08:22:33
在Oracle数据库10g中,提供了函数对于SCN和时间戳进行相互转换(作为对于闪回操作的一个增强),本文将通过一个示例进行具体分析:

具体示例如下:

第一步,我门可以通过dbms_flashback.get_system_change_number获得系统当前的SCN值:

SQL> col scn for 9999999999999SQL> select dbms_flashback.get_system_change_number scn from dual;SCN--------------8908390522972

然后,通过scn_to_timestamp函数可以将SCN转换为时间戳:

SQL> select scn_to_timestamp(8908390522972) scn from dual;SCN-----------------------------------------------------------05-JAN-07 10.56.30.000000000 AM

此处,可以通过timestamp_to_scn可以将时间戳转换为SCN:

SQL> select timestamp_to_scn(scn_to_timestamp(8908390522972)) scn from dual; SCN--------------8908390522972

通过以上这两个函数,Oracle得以将SCN和时间的关系建立起来,而在Oracle数据库10g之前的版本,却无法通过函数转换得到SCN和时间的对应关系,一般情况下只能通过logmnr分析日志获得。

注:此类转换需要依赖于数据库内部的数据记录,对于持久的SCN则不能转换,示例如下:

SQL> select min(FIRST_CHANGE#) scn,max(FIRST_CHANGE#) scn from v$archived_log;SCN SCN------------------ ------------------8907349093953 8908393582271SQL> select scn_to_timestamp(8907349093953) scn from dual;select scn_to_timestamp(8907349093953) scn from dual*ERROR at line 1:ORA-08181: specified number is not a valid system change numberORA-06512: at 'SYS.SCN_TO_TIMESTAMP', line 1ORA-06512: at line 1SQL> select scn_to_timestamp(8908393582271) scn from dual;SCN--------------------------------------------------------05-JAN-07 11.45.50.000000000 AM

标签: Oracle 数据库