scn_to_timestamp与timestamp_to_scn的相互转化

既然前面的一些博文中提到了 scn_to_timestamp与timestamp_to_scn这两个转化函数,心里一直想着找些
空余的时间进行探究一些,他们到底是怎样地相互转换,是否受到账户更换的影响。今天专门进行了几组的测试,
发现还挺有意思的,虽然还是有点达不到预期的结果,但是告诉我们:是可以相互转换来用于闪回数据库到某个
时间点的状态。当然测试的过程中,还发现了一个新的问题,新的问题在此先只是记录下来,有待进一步的探究。

以下是我的探究过程:

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与查询到的结果吻合。

4、以下是以上4个时间点的SCN转换成与其对应的的timestamp进行了4组测试:

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组存在不同程度的误差。

通过这系列的实验,获知:我们能够知道timestamp与scn是能够相互转换的,并且转换的结果并不影响
闪回数据库的操作,只要我们通过多次闪回,确保减少时间点上的误差,是能够保证闪回的数据库的数据丢失率小。

从以下的一组转换结果得知,凌晨操作的数据对应的时间点,系统记录得时间为 04-OCT-16 12.17.43.000000000 AM。
不是预想的04-OCT-16 00.17.43.000000000 AM。这是新发现的问题。

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/

你可能感兴趣的:(scn_to_timestamp与timestamp_to_scn的相互转化)