1, systimestamp与sysdate
SQL>select systimestamp - interval '1' hour from dual;
SYSTIMESTAMP-INTERVAL'1'HOUR
---------------------------------------------------------------------------
23-JUN-12 09.59.47.706252000 AM +08:00
SQL>select sysdate - interval '1' hour from dual;
SYSDATE-INTERVAL'1'
-------------------
2012-06-23 09:59:54
2, smon_scn_time,timestamp_to_scn,scn_to_timestamp,函数转换是基于smon_scn_time表的记录.
SQL>select time_dp,scn from smon_scn_time where time_dp > to_timestamp('2012-06-20','yyyy-mm-dd')
order by 1;
SQL>select timestamp_to_scn(to_timestamp('2012-06-23 10:21:00','yyyy-mm-dd
hh24:mi:ss')) from dual;
TIMESTAMP_TO_SCN(TO_TIMESTAMP('2012-06-2310:21:00','YYYY-MM-DDHH24:MI:SS'))
---------------------------------------------------------------------------
7448869
SQL>select scn_to_timestamp(7413120) from dual;
SCN_TO_TIMESTAMP(7413120)
---------------------------------------------------------------------------
20-JUN-12 08.50.57.000000000 PM
23-JUN-12 HR @ itods>delete join3 where id=3;
23-JUN-12 HR @ itods>select timestamp_to_scn(to_timestamp('2012-06-23 17:43:19','yyyy-mm-dd hh24:mi:ss')) from dual;
TIMESTAMP_TO_SCN(TO_TIMESTAMP('2012-06-2317:43:19','YYYY-MM-DDHH24:MI:SS'))
---------------------------------------------------------------------------
5437878
23-JUN-12 HR @ itods>select scn_to_timestamp(5437878) from dual;
SCN_TO_TIMESTAMP(5437878)
---------------------------------------------------------------------------
23-JUN-12 05.43.17.000000000 PM
23-JUN-12 HR @ itods>select * from join3 as of timestamp to_timestamp('2012-06-23 17:43:19','yyyy-mm-dd hh24:mi:ss');
ID CONTENT
---------- --------------------
1 txt1
2 txt2
3 txt3
23-JUN-12 HR @ itods>select * from join3 as of timestamp to_timestamp('2012-06-23 17:43:20','yyyy-mm-dd hh24:mi:ss');
ID CONTENT
---------- --------------------
1 txt1
2 txt2

本文介绍了Oracle数据库中时间戳与系统更改号(SCN)之间的转换方法,包括使用systimestamp与sysdate的区别,以及如何利用timestamp_to_scn与scn_to_timestamp函数进行转换。此外,还通过实例展示了如何基于时间戳进行闪回查询。
999

被折叠的 条评论
为什么被折叠?



