ORA_ROWSCN
这是一个非常重要的特性。从oracle10g开始,oracle在表上引入了一个伪列ORA_ROWSCN。该列记录了每一列最后更改的SCN。但是有两种模式,一种是默认的是data block级别,另一种是row级别,需要在建立表的时候指定ROWDEPENDENCIES,而且不能在表创建后用alter table语句去更改。
我们知道默认情况下SCN存储在data block的头部。这里记载的是该data block的最新更改的SCN。所以默认情况下,你去查一个表的ORA_ROWSCN,同数据块的值是相同的。如下:
SQL> create table test (id number,val char(2000));
SQL> insert into test(id , val) select rownum,object_name from dba_objects where rownum<20;
SQL> select id , dbms_rowid.rowid_block_number(ROWID),ora_rowscn,scn_to_timestamp(ora_rowscn) from test; ID DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) ORA_ROWSCN SCN_TO_TIMESTAMP(ORA_ROWSCN)
---------- ------------------------------------ ---------- ---------------------------------------------------------------------------
1 60754 618028 08-AUG-14 03.40.58.000000000 PM
2 60754 618028 08-AUG-14 03.40.58.000000000 PM
3 60754 618028 08-AUG-14 03.40.58.000000000 PM
4 60755 618028 08-AUG-14 03.40.58.000000000 PM
5 60755 618028 08-AUG-14 03.40.58.000000000 PM
6 60755 618028 08-AUG-14 03.40.58.000000000 PM
7 60756 618028 08-AUG-14 03.40.58.000000000 PM
8 60756 618028 08-AUG-14 03.40.58.000000000 PM
9 60756 618028 08-AUG-14 03.40.58.000000000 PM
10 60757 618028 08-AUG-14 03.40.58.000000000 PM
11 60757 618028 08-AUG-14 03.40.58.000000000 PM
12 60757 618028 08-AUG-14 03.40.58.000000000 PM
13 60758 618028 08-AUG-14 03.40.58.000000000 PM
14 60758 618028 08-AUG-14 03.40.58.000000000 PM
15 60758 618028 08-AUG-14 03.40.58.000000000 PM
16 60759 618028 08-AUG-14 03.40.58.000000000 PM
17 60759 618028 08-AUG-14 03.40.58.000000000 PM
18 60759 618028 08-AUG-14 03.40.58.000000000 PM
19 60760 618028 08-AUG-14 03.40.58.000000000 PM
上面是准备工作,创建一个表,该表有多个数据块,接下来我们把id=18这一列update看一下结果。
SQL> update test set id=118 where id=18; 1 row updated. SQL> select id , dbms_rowid.rowid_block_number(ROWID),ora_rowscn,scn_to_timestamp(ora_rowscn) from test; ID DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) ORA_ROWSCN SCN_TO_TIMESTAMP(ORA_ROWSCN)
---------- ------------------------------------ ---------- ---------------------------------------------------------------------------
1 60754 618028 08-AUG-14 03.40.58.000000000 PM
2 60754 618028 08-AUG-14 03.40.58.000000000 PM
3 60754 618028 08-AUG-14 03.40.58.000000000 PM
4 60755 618028 08-AUG-14 03.40.58.000000000 PM
5 60755 618028 08-AUG-14 03.40.58.000000000 PM
6 60755 618028 08-AUG-14 03.40.58.000000000 PM
7 60756 618028 08-AUG-14 03.40.58.000000000 PM
8 60756 618028 08-AUG-14 03.40.58.000000000 PM
9 60756 618028 08-AUG-14 03.40.58.000000000 PM
10 60757 618028 08-AUG-14 03.40.58.000000000 PM
11 60757 618028 08-AUG-14 03.40.58.000000000 PM
12 60757 618028 08-AUG-14 03.40.58.000000000 PM
13 60758 618028 08-AUG-14 03.40.58.000000000 PM
14 60758 618028 08-AUG-14 03.40.58.000000000 PM
15 60758 618028 08-AUG-14 03.40.58.000000000 PM
16 60759 618028 08-AUG-14 03.40.58.000000000 PM
17 60759 618028 08-AUG-14 03.40.58.000000000 PM
118 60759 618028 08-AUG-14 03.40.58.000000000 PM
19 60760 618028 08-AUG-14 03.40.58.000000000 PM 19 rows selected.
现在还没有commit。但是按照猜想这60759这个数据块对应的列的SCN都应该变了。不过实际没有变,不知道为什么,需要再研究,不过我们commit一下就会变了。
SQL> commit; Commit complete. SQL> select id , dbms_rowid.rowid_block_number(ROWID),ora_rowscn,scn_to_timestamp(ora_rowscn) from test; ID DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) ORA_ROWSCN SCN_TO_TIMESTAMP(ORA_ROWSCN)
---------- ------------------------------------ ---------- ---------------------------------------------------------------------------
1 60754 618028 08-AUG-14 03.40.58.000000000 PM
2 60754 618028 08-AUG-14 03.40.58.000000000 PM
3 60754 618028 08-AUG-14 03.40.58.000000000 PM
4 60755 618028 08-AUG-14 03.40.58.000000000 PM
5 60755 618028 08-AUG-14 03.40.58.000000000 PM
6 60755 618028 08-AUG-14 03.40.58.000000000 PM
7 60756 618028 08-AUG-14 03.40.58.000000000 PM
8 60756 618028 08-AUG-14 03.40.58.000000000 PM
9 60756 618028 08-AUG-14 03.40.58.000000000 PM
10 60757 618028 08-AUG-14 03.40.58.000000000 PM
11 60757 618028 08-AUG-14 03.40.58.000000000 PM
12 60757 618028 08-AUG-14 03.40.58.000000000 PM
13 60758 618028 08-AUG-14 03.40.58.000000000 PM
14 60758 618028 08-AUG-14 03.40.58.000000000 PM
15 60758 618028 08-AUG-14 03.40.58.000000000 PM
16 60759 618251 08-AUG-14 03.45.28.000000000 PM
17 60759 618251 08-AUG-14 03.45.28.000000000 PM
118 60759 618251 08-AUG-14 03.45.28.000000000 PM
19 60760 618028 08-AUG-14 03.40.58.000000000 PM
我们再看一下row级别的。
SQL> create table test (id number,val char(2000)) rowdependencies ; Table created. SQL> insert into test(id , val) select rownum,object_name from dba_objects where rownum<20; 19 rows created. SQL> commit; Commit complete. SQL> select id , dbms_rowid.rowid_block_number(ROWID),ora_rowscn,scn_to_timestamp(ora_rowscn) from test; ID DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) ORA_ROWSCN SCN_TO_TIMESTAMP(ORA_ROWSCN)
---------- ------------------------------------ ---------- ---------------------------------------------------------------------------
1 60754 618618 08-AUG-14 03.57.40.000000000 PM
2 60754 618618 08-AUG-14 03.57.40.000000000 PM
3 60754 618618 08-AUG-14 03.57.40.000000000 PM
4 60755 618618 08-AUG-14 03.57.40.000000000 PM
5 60755 618618 08-AUG-14 03.57.40.000000000 PM
6 60755 618618 08-AUG-14 03.57.40.000000000 PM
7 60756 618618 08-AUG-14 03.57.40.000000000 PM
8 60756 618618 08-AUG-14 03.57.40.000000000 PM
9 60756 618618 08-AUG-14 03.57.40.000000000 PM
10 60757 618618 08-AUG-14 03.57.40.000000000 PM
11 60757 618618 08-AUG-14 03.57.40.000000000 PM
12 60757 618618 08-AUG-14 03.57.40.000000000 PM
13 60758 618618 08-AUG-14 03.57.40.000000000 PM
14 60758 618618 08-AUG-14 03.57.40.000000000 PM
15 60758 618618 08-AUG-14 03.57.40.000000000 PM
16 60759 618618 08-AUG-14 03.57.40.000000000 PM
17 60759 618618 08-AUG-14 03.57.40.000000000 PM
18 60759 618618 08-AUG-14 03.57.40.000000000 PM
19 60760 618618 08-AUG-14 03.57.40.000000000 PM 19 rows selected. SQL> update test set id=888 where id=18; 1 row updated. SQL> select id , dbms_rowid.rowid_block_number(ROWID),ora_rowscn,scn_to_timestamp(ora_rowscn) from test; ID DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) ORA_ROWSCN SCN_TO_TIMESTAMP(ORA_ROWSCN)
---------- ------------------------------------ ---------- ---------------------------------------------------------------------------
1 60754 618618 08-AUG-14 03.57.40.000000000 PM
2 60754 618618 08-AUG-14 03.57.40.000000000 PM
3 60754 618618 08-AUG-14 03.57.40.000000000 PM
4 60755 618618 08-AUG-14 03.57.40.000000000 PM
5 60755 618618 08-AUG-14 03.57.40.000000000 PM
6 60755 618618 08-AUG-14 03.57.40.000000000 PM
7 60756 618618 08-AUG-14 03.57.40.000000000 PM
8 60756 618618 08-AUG-14 03.57.40.000000000 PM
9 60756 618618 08-AUG-14 03.57.40.000000000 PM
10 60757 618618 08-AUG-14 03.57.40.000000000 PM
11 60757 618618 08-AUG-14 03.57.40.000000000 PM
12 60757 618618 08-AUG-14 03.57.40.000000000 PM
13 60758 618618 08-AUG-14 03.57.40.000000000 PM
14 60758 618618 08-AUG-14 03.57.40.000000000 PM
15 60758 618618 08-AUG-14 03.57.40.000000000 PM
ERROR:
ORA-01405: fetched column value is NULL 15 rows selected. SQL> commit; Commit complete. SQL> select id , dbms_rowid.rowid_block_number(ROWID),ora_rowscn,scn_to_timestamp(ora_rowscn) from test; ID DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) ORA_ROWSCN SCN_TO_TIMESTAMP(ORA_ROWSCN)
---------- ------------------------------------ ---------- ---------------------------------------------------------------------------
1 60754 618618 08-AUG-14 03.57.40.000000000 PM
2 60754 618618 08-AUG-14 03.57.40.000000000 PM
3 60754 618618 08-AUG-14 03.57.40.000000000 PM
4 60755 618618 08-AUG-14 03.57.40.000000000 PM
5 60755 618618 08-AUG-14 03.57.40.000000000 PM
6 60755 618618 08-AUG-14 03.57.40.000000000 PM
7 60756 618618 08-AUG-14 03.57.40.000000000 PM
8 60756 618618 08-AUG-14 03.57.40.000000000 PM
9 60756 618618 08-AUG-14 03.57.40.000000000 PM
10 60757 618618 08-AUG-14 03.57.40.000000000 PM
11 60757 618618 08-AUG-14 03.57.40.000000000 PM
12 60757 618618 08-AUG-14 03.57.40.000000000 PM
13 60758 618618 08-AUG-14 03.57.40.000000000 PM
14 60758 618618 08-AUG-14 03.57.40.000000000 PM
15 60758 618618 08-AUG-14 03.57.40.000000000 PM
16 60759 618618 08-AUG-14 03.57.40.000000000 PM
17 60759 618618 08-AUG-14 03.57.40.000000000 PM
888 60759 618643 08-AUG-14 03.58.28.000000000 PM
19 60760 618618 08-AUG-14 03.57.40.000000000 PM 19 rows selected.
先创建一个表,指定rowdependencies 然后插入数值。
我们先更新了一列,没commit,然后去select。有意思的是这里出了个错误,很值得研究。
然后我们commit后发现这一列的更改时间知道了。
ORA_ROWSCN的更多相关文章
- oracle ORA_ROWSCN 行记录的更新时间
在这介绍两个oracle 10G开始提供的一个伪列ORA_ROWSCN,它又分为两种模式一种是基于block,这是默认的模式,还有一种是基于row上,这种模式只能在建里表时指定ROWDEPENDENC ...
- oracle行跟踪(基于行跟踪的ROWDEPENDENCIES ORA_ROWSCN信息)
在Oracle 10g中的引入了ORA_ROWSCN伪列新特性.基于此种伪列所提供的信息,我们可以方便地找出某个数据块或某一个行最近被修改的时间戳.在默认情况下,10g下表会以非行依赖性(NOROWD ...
- Oracle 中的伪列
昨天做了一个Oracle PL/SQL 相关的测试,其中有一道这样的题目: 下列那些是Oracle的伪列(ACD) A.ROWID B.ROW_NUMBER() C.LEVEL D.RO ...
- oracle 关键字
Oracle 关键字(保留字) DBA账户下执行SQL语句:select * from v$reserved_words ; 可得到所有的关键字: 1 ! 1 2 & 1 3 ( 1 4 ...
- 如何查看oracle数据库的所有的关键字
管理员账户登录后,执行以下命令: select * from v$reserved_words 附上参考: NOMONITORINGRECORDS_PER_BLOCKCASCADEDYNAMIC_S ...
- ORACLE恢复数据
ORACLE恢复删除表或表记录 一:表的恢复 对误删的表,只要没有使用PURGE永久删除选项,那么从flash back区恢复回来希望是挺大的.一般步骤有: 1.从flash back里查询 ...
- 【锁】Oracle锁系列
[锁]Oracle锁系列 1 BLOG文档结构图 2 前言部分 2.1 导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识,~O(∩_∩)O~: ...
- Oracle的悲观锁和乐观锁---摘抄
1.无论是选择悲观锁策略,还是乐观锁策略.如果一个对象被上了锁,那么该对象都会受这个锁的控制和影响.如果这个锁是个排它锁,那么其它会话都不能修改它. 2.选择悲观锁策略,还是乐观锁策略,这主要是由应用 ...
- oracle触发器如何使用2
触发器 是特定事件出现的时候,自动执行的代码块.类似于存储过程,但是用户不能直接调用他们.触发器是许多关系数据库系统都提供的一项技术.在ORACLE系统里,触发器类似过程和函数,都有声明,执行和异常处 ...
随机推荐
- CSS动画持续汇总中
一:向上的动态箭头------------------http://www.5599.com/88lz/up_direct.html
- c# Queue实现生产者(Producer)消费者(Consumer)模式
我们在开发过程中经常会遇到需要从一个地方不断获取数据然后又需要交给另一个线程对数据进行二次加工的情况,这种场景适合使用生产者-消费者模式. Demo展示 //中间的容器 public static c ...
- 6.13---shiro
- dubbo面试题
40 道 Dubbo 面试题及答案:https://blog.csdn.net/BinshaoNo_1/article/details/83024303 (原地址奉上:https://mp.weixi ...
- LN : leetcode 515 Find Largest Value in Each Tree Row
lc 515 Find Largest Value in Each Tree Row 515 Find Largest Value in Each Tree Row You need to find ...
- MySQL 帮助类 MySQLHelper
/// <summary> /// MySqlHelper操作类 /// </summary> public sealed partial class MySQLHelper ...
- PHP7 上传文件报错 Internal Server Error 解决方法
打开Apache配置httpd.conf.在最后添加FcgidMaxRequestLen指令一个足够大的值(以字节为单位),例如 FcgidMaxRequestLen 100000000 最后重新启动 ...
- Codeforces_765_D. Artsem and Saunders_(数学)
D. Artsem and Saunders time limit per test 2 seconds memory limit per test 512 megabytes input stand ...
- 使用python获得N个区分度较高的RGB颜色值
获得任意N个区分度最高的RGB颜色值是一个经典的问题,之前在做一些可视化的东西时需要解决这个问题.首先去网上找了一些方法,未果,于是想自己来搞,心里的想法是,先给出一个距离函数用来度量两个RGB颜色值 ...
- 05Servlet example
dgdfgdfggggggg Servlet 表单数据 在客户端,GET通过URL提交数据,数据在URL中可见:POST把数据放在form的数据体内提交.GET提交的数据最多只有1024字节:POST ...