scn与timestamp的相互转换

来源:互联网 发布:桌面图标收纳软件 编辑:程序博客网 时间:2024/06/11 21:55
SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
Session altered.

SQL> alter session set nls_language=american;
Session altered.

SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'; //设置时间显示格式
Session altered.

SQL> select sysdate from dual;//查询当前系统时间
SYSDATE
-------------------
2013-05-30 11:50:46
SQL> select to_timestamp('2013-05-30 11:50:46','yyyy-mm-dd hh24:mi:ss') from dual; //将上面查询的时间转为时间戳记
TO_TIMESTAMP('2013-05-3011:50:46','YYYY-MM-DDHH24:MI:SS')
---------------------------------------------------------------------------
30-MAY-13 11.50.46.000000000 AM

SQL> select timestamp_to_scn('30-MAY-13 11.50.46.000000000 AM') from dual; //将时间戳记转为scn号
TIMESTAMP_TO_SCN('30-MAY-1311.50.46.000000000AM')
-------------------------------------------------
                                          4950772
                                          
SQL> select scn_to_timestamp(4950772) from dual; //将scn号转为时间戳记
SCN_TO_TIMESTAMP(4950772)
------------------------------------------------
30-MAY-13 11.50.44.000000000 AM

获取当前scn:
SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
                 4951211

SQL> select current_scn from v$database;
CURRENT_SCN
-----------
    4951287
原创粉丝点击