Home > Database > Mysql Tutorial > body text

Oracle 10g中SCN与TimeStamp的相互转换

WBOY
Release: 2016-06-07 17:07:29
Original
862 people have browsed it

首先通过dbms_flashback.get_system_change_number 可以获得系统当前的SCN值: SQLgt; col scn for 9999999999999SQLgt; selec

首先通过dbms_flashback.get_system_change_number 可以获得系统当前的SCN值:


SQL> col scn for 9999999999999
SQL> 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和时间的关系建立起来,,在Oracle10g之前,是没有办法通过函数转换得到SCN和时间的对应关系的,一般可以通过logmnr分析日志获得。

但是这种转换要依赖于数据库内部的数据记录,对于久远的SCN则不能转换,请看以下举例:


SQL> select min(FIRST_CHANGE#) scn,max(FIRST_CHANGE#) scn from v$archived_log;
SCN SCN
------------------ ------------------
8907349093953 8908393582271

SQL> 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 number
ORA-06512: at "SYS.SCN_TO_TIMESTAMP", line 1
ORA-06512: at line 1


SQL> select scn_to_timestamp(8908393582271) scn from dual;

SCN
---------------------------------------------------------------------------
05-JAN-07 11.45.50.000000000 AM

-The End-

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!