使用ORA_ROWSCN的乐观锁定
mld
@ORCL
>
drop
table
dept;
表已删除。
mld @ORCL > create table dept
2 (deptno, dname, loc, data,
3 constraint dept_pk primary key (deptno)
4 )
5 as
6 select deptno, dname, loc, rpad( ' * ' , 3500 , ' * ' )
7 from scott.dept;
表已创建。
mld @ORCL > select deptno, dname,
2 dbms_rowid.rowid_block_number(rowid) blockno,
3 ora_rowscn
4 from dept;
DEPTNO DNAME BLOCKNO ORA_ROWSCN
-- -------- -------------- ---------- ----------
10 ACCOUNTING 156868 1564176
20 RESEARCH 156868 1564176
30 SALES 156869 1564176
40 OPERATIONS 156869 1564176
mld @ORCL > update dept
2 set dname = lower (dname)
3 where deptno = 10 ;
已更新 1 行。
mld @ORCL > commit ;
提交完成。
mld @ORCL > select deptno, dname,
2 dbms_rowid.rowid_block_number(rowid) blockno,
3 ora_rowscn
4 from dept;
DEPTNO DNAME BLOCKNO ORA_ROWSCN
-- -------- -------------- ---------- ----------
10 accounting 156868 1564229
20 RESEARCH 156868 1564229
30 SALES 156869 1564176
40 OPERATIONS 156869 1564176
mld @ORCL >
--默认:ORA_ROWSCN在块级维护。
要使ORA_ROWSCN在行级维护,需要重建表,启用ROWDEPENDENCIES (或者用DBMS_REDEFINITION中的在线重建功能)。
表已删除。
mld @ORCL > create table dept
2 (deptno, dname, loc, data,
3 constraint dept_pk primary key (deptno)
4 )
5 as
6 select deptno, dname, loc, rpad( ' * ' , 3500 , ' * ' )
7 from scott.dept;
表已创建。
mld @ORCL > select deptno, dname,
2 dbms_rowid.rowid_block_number(rowid) blockno,
3 ora_rowscn
4 from dept;
DEPTNO DNAME BLOCKNO ORA_ROWSCN
-- -------- -------------- ---------- ----------
10 ACCOUNTING 156868 1564176
20 RESEARCH 156868 1564176
30 SALES 156869 1564176
40 OPERATIONS 156869 1564176
mld @ORCL > update dept
2 set dname = lower (dname)
3 where deptno = 10 ;
已更新 1 行。
mld @ORCL > commit ;
提交完成。
mld @ORCL > select deptno, dname,
2 dbms_rowid.rowid_block_number(rowid) blockno,
3 ora_rowscn
4 from dept;
DEPTNO DNAME BLOCKNO ORA_ROWSCN
-- -------- -------------- ---------- ----------
10 accounting 156868 1564229
20 RESEARCH 156868 1564229
30 SALES 156869 1564176
40 OPERATIONS 156869 1564176
mld @ORCL >
--默认:ORA_ROWSCN在块级维护。
mld
@ORCL
>
drop
table
dept;
表已删除。
mld @ORCL > create table dept
2 (deptno, dname, loc, data,
3 constraint dept_pk primary key (deptno)
4 )
5 as
6 select deptno, dname, loc, rpad( ' * ' , 3500 , ' * ' )
7 from scott.dept;
表已创建。
mld @ORCL > select deptno, dname,
2 dbms_rowid.rowid_block_number(rowid) blockno,
3 ora_rowscn
4 from dept;
DEPTNO DNAME BLOCKNO ORA_ROWSCN
-- -------- -------------- ---------- ----------
10 ACCOUNTING 156868 1564176
20 RESEARCH 156868 1564176
30 SALES 156869 1564176
40 OPERATIONS 156869 1564176
mld @ORCL > update dept
2 set dname = lower (dname)
3 where deptno = 10 ;
已更新 1 行。
mld @ORCL > commit ;
提交完成。
mld @ORCL > select deptno, dname,
2 dbms_rowid.rowid_block_number(rowid) blockno,
3 ora_rowscn
4 from dept;
DEPTNO DNAME BLOCKNO ORA_ROWSCN
-- -------- -------------- ---------- ----------
10 accounting 156868 1564229
20 RESEARCH 156868 1564229
30 SALES 156869 1564176
40 OPERATIONS 156869 1564176
mld @ORCL >
mld @ORCL >
mld @ORCL >
mld @ORCL >
mld @ORCL > drop table dept;
表已删除。
mld @ORCL > create table dept
2 (deptno, dname, loc, data,
3 constraint dept_pk primary key (deptno)
4 )
5 ROWDEPENDENCIES
6 as
7 select deptno, dname, loc, rpad( ' * ' , 3500 , ' * ' )
8 from scott.dept;
表已创建。
mld @ORCL > select deptno, dname,
2 dbms_rowid.rowid_block_number(rowid) blockno,
3 ora_rowscn
4 from dept;
DEPTNO DNAME BLOCKNO ORA_ROWSCN
-- -------- -------------- ---------- ----------
10 ACCOUNTING 156884 1564527
20 RESEARCH 156884 1564527
30 SALES 156885 1564527
40 OPERATIONS 156885 1564527
mld @ORCL > update dept
2 set dname = lower (dname)
3 where deptno = 10 ;
已更新 1 行。
mld @ORCL > commit ;
提交完成。
mld @ORCL > select deptno, dname,
2 dbms_rowid.rowid_block_number(rowid) blockno,
3 ora_rowscn
4 from dept;
DEPTNO DNAME BLOCKNO ORA_ROWSCN
-- -------- -------------- ---------- ----------
10 accounting 156884 1564550
20 RESEARCH 156884 1564527
30 SALES 156885 1564527
40 OPERATIONS 156885 1564527
mld @ORCL >
表已删除。
mld @ORCL > create table dept
2 (deptno, dname, loc, data,
3 constraint dept_pk primary key (deptno)
4 )
5 as
6 select deptno, dname, loc, rpad( ' * ' , 3500 , ' * ' )
7 from scott.dept;
表已创建。
mld @ORCL > select deptno, dname,
2 dbms_rowid.rowid_block_number(rowid) blockno,
3 ora_rowscn
4 from dept;
DEPTNO DNAME BLOCKNO ORA_ROWSCN
-- -------- -------------- ---------- ----------
10 ACCOUNTING 156868 1564176
20 RESEARCH 156868 1564176
30 SALES 156869 1564176
40 OPERATIONS 156869 1564176
mld @ORCL > update dept
2 set dname = lower (dname)
3 where deptno = 10 ;
已更新 1 行。
mld @ORCL > commit ;
提交完成。
mld @ORCL > select deptno, dname,
2 dbms_rowid.rowid_block_number(rowid) blockno,
3 ora_rowscn
4 from dept;
DEPTNO DNAME BLOCKNO ORA_ROWSCN
-- -------- -------------- ---------- ----------
10 accounting 156868 1564229
20 RESEARCH 156868 1564229
30 SALES 156869 1564176
40 OPERATIONS 156869 1564176
mld @ORCL >
mld @ORCL >
mld @ORCL >
mld @ORCL >
mld @ORCL > drop table dept;
表已删除。
mld @ORCL > create table dept
2 (deptno, dname, loc, data,
3 constraint dept_pk primary key (deptno)
4 )
5 ROWDEPENDENCIES
6 as
7 select deptno, dname, loc, rpad( ' * ' , 3500 , ' * ' )
8 from scott.dept;
表已创建。
mld @ORCL > select deptno, dname,
2 dbms_rowid.rowid_block_number(rowid) blockno,
3 ora_rowscn
4 from dept;
DEPTNO DNAME BLOCKNO ORA_ROWSCN
-- -------- -------------- ---------- ----------
10 ACCOUNTING 156884 1564527
20 RESEARCH 156884 1564527
30 SALES 156885 1564527
40 OPERATIONS 156885 1564527
mld @ORCL > update dept
2 set dname = lower (dname)
3 where deptno = 10 ;
已更新 1 行。
mld @ORCL > commit ;
提交完成。
mld @ORCL > select deptno, dname,
2 dbms_rowid.rowid_block_number(rowid) blockno,
3 ora_rowscn
4 from dept;
DEPTNO DNAME BLOCKNO ORA_ROWSCN
-- -------- -------------- ---------- ----------
10 accounting 156884 1564550
20 RESEARCH 156884 1564527
30 SALES 156885 1564527
40 OPERATIONS 156885 1564527
mld @ORCL >