oracle闪回查询加条件,关于闪回查询的问题,谢谢!!!

原帖由 lozity 于 2009-1-3 16:20 发表 thread-1108912-1-1.html

1、scn_to_timestamp和timestamp_to_scn是基于sys.smon_scn_time表,对吧?为什么我第二个查询可以得到结果呢?

SQL> select scn_to_timestamp(max(scn)+180) c,scn_to_timestamp(max(scn)) d from sys.smon_scn_time;

select scn_to_timestamp(max(scn)+180) c,scn_to_timestamp(max(scn)) d from sys.smon_scn_time

*

ERROR at line 1:

ORA-08181: specified number is not a valid system change number

ORA-06512: at "SYS.SCN_TO_TIMESTAMP", line 1

SQL> select scn_to_timestamp(max(scn)+120) c,scn_to_timestamp(max(scn)) d from sys.smon_scn_time;

C                                             D

--------------------------------------------- ---------------------------------------------

03-JAN-09 03.29.41.000000000 PM               03-JAN-09 03.24.17.000000000 PM

2、我把下列脚本复制到10g的sqlplus窗口中执行:

create table h(id number);

insert into h values(1);

commit;

select * from h as of scn(sys.dbms_flashback.get_system_change_number);

返回错误如下:

ERROR at line 1:

ORA-01466: unable to read data - table definition has changed

然后我再把下列脚本复制进去执行:

insert into h select * from h;

commit;

select * from h as of scn(sys.dbms_flashback.get_system_change_number);

就没有出错,正常返回了表h中的两条记录,哪位dx可以解释下?谢谢。。。

你这问题老搞笑,我一直没看明白你这么做的目的,是要试验什么效果?来看看我的试验结果:

SQL> select dbms_flashback.get_system_change_number from dual;

GET_SYSTEM_CHANGE_NUMBER

------------------------

473009

SQL> create table h(id number);

表已创建。

SQL> insert into h values(1);

已创建 1 行。

SQL> commit;

提交完成。

SQL> select dbms_flashback.get_system_change_number from dual;

GET_SYSTEM_CHANGE_NUMBER

------------------------

474928

SQL> select ora_rowscn,h.* from h;

ORA_ROWSCN         ID

---------- ----------

474926          1

SQL> select * from h;

ID

----------

1

SQL> select * from h as of scn 474926;

ID

----------

1

SQL> select * from h as of scn 474928;

ID

----------

1

SQL> select * from h as of scn 473009;

select * from h as of scn 473009

*

第 1 行出现错误:

ORA-01466: 无法读取数据 - 表定义已更改

SQL> select * from h as of scn(dbms_flashback.get_system_change_number);

ID

----------

1

SQL> select * from h as of scn 474924;

未选定行

SQL> select * from h as of scn 474925;

未选定行

SQL>

再来创建一个表试试看:

SQL> create table h1(id number);

表已创建。

SQL> commit;

提交完成。

SQL> select dbms_flashback.get_system_change_number from dual;

GET_SYSTEM_CHANGE_NUMBER

------------------------

475106

SQL> select ora_rowscn,h1.* from h1;

未选定行

SQL> insert into h1 values(1);

已创建 1 行。

SQL> commit;

提交完成。

SQL> select ora_rowscn,h1.* from h1;

ORA_ROWSCN         ID

---------- ----------

475118          1

SQL> select dbms_flashback.get_system_change_number from dual;

GET_SYSTEM_CHANGE_NUMBER

------------------------

475123

SQL> select * from h1 as of scn 475123;

ID

----------

1

SQL> select * from h1 as of scn 475118;

ID

----------

1

SQL> select * from h1 as of scn 475106;

未选定行

SQL> select * from h1 as of scn 475104;

未选定行

SQL> select * from h1 as of scn 475102;

select * from h1 as of scn 475102

*

第 1 行出现错误:

ORA-01466: 无法读取数据 - 表定义已更改

SSQL> select dbms_flashback.get_system_change_number from dual;

GET_SYSTEM_CHANGE_NUMBER

------------------------

475156

SQL> select * from h1 as of scn 475256;

select * from h1 as of scn 475256

*

第 1 行出现错误:

ORA-08181: 指定的编号不是有效的系统更改号

SQL>

所以说,我真看不明白你做了什么也不知道你想要做什么我按照你的思路去做什么都没有问题。

如果你想问闪回查询允许最小或者最大的SCN的话,那么很明白,允许闪回查询的最小SCN就是三种之一:1,v$archived_log的max(RESETLOGS_CHANGE#)。2,建表时的SCN,小于它则不能获得表定义了。3,UNDO里的记录,若数据库版本>10G,则看闪回区里记录的数据了,还跟db_recovery_file_dest_size这个参数有关系。

而最大SCN就没啥意义,闪回查询是恢复历史数据用的,最大SCN只要不超出当前SCN就没问题。

[本帖最后由 david3389 于 2009-1-4 10:56 编辑]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值