mysql的rowscn_OracleORA_ROWSCN伪列说明

也就是说,使用表的默认创建参数,即norowdependencies时,此时的ora_rawscn 取自data block header的SCN,那么这时候,对于同一

一. 官网对该伪列的说明

From:11gR2

Oracle.com/docs/cd/E11882_01/server.112/e17118/pseudocolumns007.htm#SQLRF50953

Foreach row, ORA_ROWSCN returns the conservative upper bound system change number(SCN) of the most recent change to the row in the current session. Thispseudocolumn is useful for determining approximately when a row was lastupdated.

Itis not absolutely precise, because Oracle tracks SCNs by transaction committedfor the block in which the row resides. You can obtain a more fine-grainedapproximation of the SCN by creating your tables with row-level dependencytracking. Refer to CREATE TABLE ... for more information on row-level dependency tracking.

ROWDEPENDENCIESSpecify ROWDEPENDENCIES if you want to enable row-level dependency tracking.This setting is useful primarily to allow for parallel propagation inreplication environments. It increases the size of each row by 6 bytes.

NOROWDEPENDENCIESSpecify NOROWDEPENDENCIES if you do not want table to use the row-leveldependency tracking feature. This is the default.

也就是说,使用表的默认创建参数,即norowdependencies时,此时的ora_rawscn 取自data block header的SCN,那么这时候,对于同一个block里的row而言,他们的ora_rowscn 是一样的。

而在创建table时指定为rowdependencies时,那么会为每行row 保存一个ora_rowscn. 这样对于同一个block里的row,会有多个ora_rowscn 值。通过dump block,可以发现每个row 会多出一个dscn的信息,该信息就是用来保存ora_rowscn的。

如:

tab 0, row 1, @0×1f88

tl: 12 fb: –H-FL– lb: 0×2 cc: 1

dscn 0×0000.00000000

tab 0, row 1, @0×1f88

tl: 12 fb: –H-FL– lb: 0×0 cc: 1

dscn 0×0005.105a6cc1

这是同一个row的dump 信息,第一次dscn 为0. 此时信息是从itl的Scn/Fsc中获得的,当itl发生cleanout时会把Scn/Fsc刷到dscn,就是上面的第二段信息。具体这块后面会实验证明。

关于block dump 和 itl 说明,参考:

Oracle datafile block 格式 说明

Orace ITL(InterestedTransaction List) 说明

You cannot use this pseudocolumn in a query to a view.However, you can use it to refer to the underlying table when creating a view.You can also use this pseudocolumn in the WHERE clause of an UPDATE or DELETEstatement.

--不能在视图使用ora_rowscn伪列

ORA_ROWSCN is not supported for Flashback Query.Instead, use the version query pseudocolumns, which are provided explicitly forFlashback Query. Refer to the SELECT ... for information on Flashback Query and for additional information on thosepseudocolumns.

--ora_rowscn 不支持Flashbackquery。

Restriction on ORA_ROWSCN: This pseudocolumn is notsupported for external tables.

--ora_rowscn 不支持外部表

Example:

Thefirst statement below uses the ORA_ROWSCN pseudocolumn to get the system changenumber of the last operation on the employees table.

SELECT ORA_ROWSCN, last_name

FROM employees

WHERE employee_id = 188;

--使用ORA_ROWSCN获取该row 最后一次更新时的SCN

The second statement uses the pseudocolumnwith the SCN_TO_TIMESTAMP function to determine the timestamp of the operation:

SELECTSCN_TO_TIMESTAMP(ORA_ROWSCN), last_name

FROM employees

WHERE employee_id = 188;

--使用SCN_TO_TIMESTAMP 和 ORA_ROWSCN,获取最后一次修改row的时间

二. ORA_ROWSCN 说明

ORA_ROWSCN伪列是Oracle10g引入的,可以查询表中记录最后变更的SCN。这个新的伪列在某些环境下会非常有用,比如执行乐观锁定,或者增量数据抽取的时候。但是,默认情况下,每行记录的ORA_ROWSCN是基于Block的,除非在建表的时候执行开启行级跟踪(createtable … rowdependencies)。

2.1 乐观锁和ORA_ROWSCN

需要select ... for update做悲观锁定的时候,,通过使用ORA_ROWSCN可以改成乐观锁定。一开始select数据的时候将ORA_ROWSCN查出来,修改后如果要写回数据库之前再比对下最新的ORA_ROWSCN就可以知道这期间数据是否有发生变化。

2.2 增量数据抽取和ORA_ROWSCN

每次抽取后记录最大的ORA_ROWSCN,下次抽取再基于上一次的SCN来获得最近修改过的数据即可。在10g之前,很多系统要实现增量数据抽取,要么通过解析日志,要么加触发器,要么就在表上加一个时间截字段。

ORA_ROWSCN其实就是第三种方式,只是这个字段由Oracle来维护,这样可以避免一些应用绕过时间截去更新其他字段带来的问题。不过,如果系统中使用了逻辑备库或者streams等逻辑复制的方案,而数据抽取又是基于逻辑备库的话,ORA_ROWSCN就可能对抽取后的数据分析有影响了,因为通过这个得到的时间是逻辑备库上记录变更的时间,而不是源库的时间了。

当然,如果纯粹只是做数据抽取,而不需要使用这个时间来做分析,还是问题不大的,但还是要考虑一旦逻辑备库出现故障需要重做的,则这个增量抽取要怎么来处理的问题。

logo.gif

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:php中文网

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值