1、在Scott用户下创建实验表:
create table rf_time as select * from fbdb_scn where 1=2;
insert into rf_time select 1 as id,
dbms_flashback.get_system_change_number as scn,
sysdate as dd from dual;
commit;
insert into rf_time select 2 as id,
dbms_flashback.get_system_change_number as scn,
sysdate as dd from dual;
commit;
insert into rf_time select 3 as id,
dbms_flashback.get_system_change_number as scn,
sysdate as dd from dual;
commit;
insert into rf_time select 4 as id,
dbms_flashback.get_system_change_number as scn,
sysdate as dd from dual;
commit;
SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
Session altered.
SQL> select * from rf_time;
ID SCN DD
---------- ---------- -------------------
1 803264 2016-10-04 00:17:45
2 803354 2016-10-04 00:21:58
3 803365 2016-10-04 00:22:29
4 803420 2016-10-04 00:25:03
2、根据以上实验表中的数据,在两个不同用户下进行不同的测试:
Sys用户下:
SQL> select timestamp_to_scn(to_date('2016-10-04 00:17:45','yyyy-mm-dd hh24:mi:ss')) from dual;
TIMESTAMP_TO_SCN(TO_DATE('2016-10-0400:17:45','YYYY-MM-DDHH24:MI:SS'))
----------------------------------------------------------------------
803259
Scott用户写:
SQL> select timestamp_to_scn(to_date('2016-10-04 00:17:45','yyyy-mm-dd hh24:mi:ss')) from dual;
TIMESTAMP_TO_SCN(TO_DATE('2016-10-0400:17:45','YYYY-MM-DDHH24:MI:SS'))
----------------------------------------------------------------------
803259
发现,不同用户下同一个时间点对应的scn是一样的。3、新插入一条数据,并提交,两个操作分别查询系统改变号:
SQL> insert into rf_time select 5 as id,
2 dbms_flashback.get_system_change_number as scn,
3 sysdate as dd from dual
1 row created.
SQL> select dbms_flashback.get_system_change_number as scn,sysdate as dd from dual;
SCN DD
---------- -------------------
805309 2016-10-04 11:38:21
SQL> commit
Commit complete.
SQL> select dbms_flashback.get_system_change_number as scn,sysdate as dd from dual;
SCN DD
---------- -------------------
805322 2016-10-04 11:38:50
SQL> select timestamp_to_scn(to_date('2016-10-04 11:38:21','yyyy-mm-dd hh24:mi:ss')) from dual;
TIMESTAMP_TO_SCN(TO_DATE('2016-10-0411:38:21','YYYY-MM-DDHH24:MI:SS'))
----------------------------------------------------------------------
805309
SQL> select timestamp_to_scn(to_date('2016-10-04 11:38:50','yyyy-mm-dd hh24:mi:ss')) from dual;
TIMESTAMP_TO_SCN(TO_DATE('2016-10-0411:38:50','YYYY-MM-DDHH24:MI:SS'))
----------------------------------------------------------------------
805322
发现,timestamp转换成scn与查询到的结果吻合。SQL> select scn_to_timestamp(803264) from dual;
SCN_TO_TIMESTAMP(803264)
---------------------------------------------------------------------------
04-OCT-16 12.17.43.000000000 AM
SQL> select scn_to_timestamp(803365) from dual;
SCN_TO_TIMESTAMP(803365)
---------------------------------------------------------------------------
04-OCT-16 12.22.25.000000000 AM
SQL> select scn_to_timestamp(805309) from dual;
SCN_TO_TIMESTAMP(805309)
---------------------------------------------------------------------------
04-OCT-16 11.38.21.000000000 AM
SQL> select scn_to_timestamp(805322) from dual;
SCN_TO_TIMESTAMP(805322)
---------------------------------------------------------------------------
04-OCT-16 11.38.48.000000000 AM
发现4组当中只有1组完全吻合,还有3组存在不同程度的误差。SQL> select scn_to_timestamp(803264) from dual;
SCN_TO_TIMESTAMP(803264)
---------------------------------------------------------------------------
04-OCT-16 12.17.43.000000000 AM
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31392094/viewspace-2125845/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31392094/viewspace-2125845/