OCP-1Z0-051 第157题 事务和锁
来源:互联网 发布:微博修改个性域名 编辑:程序博客网 时间:2024/06/01 22:57
一、原题
二、题目翻译
三、题目解析
四、测试
关于C选项,测试如下,选择其中一种情况,DDL的时候,会自动提交事务,并释放锁。
会话1:
SQL> select sid from v$mystat where rownum=1;
SID
----------
158
SQL> select * from emp where ename='SCOTT' for update;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- -------------------- ------------------ ---------- ------------ ---------- ---------- ----------
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
会话2中查锁的相关信息:
SQL> set linesize 150
SQL> column o_name format a10
SQL> column lock_type format a20
SQL> column object_name format a15
SQL> select sid,type,id1,id2,
2 decode(lmode,0,'None',
3 1,'Null',
4 2,'Row share',
5 3,'Row Exclusive',
6 4,'Share',
7 5,'Share Row Exclusive',
8 6,'Exclusive') lock_type,
9 request,ctime,block
10 from v$lock
11 where sid=158;
SID TYPE ID1 ID2 LOCK_TYPE REQUEST CTIME BLOCK
---------- ---- ---------- ---------- -------------------- ---------- ---------- ----------
158 TM 58060 0 Row Exclusive 0 75 0
158 TX 65540 5023 Exclusive 0 75 0
会话1中,继续进行DDL操作:
SQL> create table test_lock(id int);
Table created.
会话2中再查锁的相关信息,就没有了,说明DDL操作也会导致事务结束,这里是自动提交了:
SQL> select sid,type,id1,id2,
2 decode(lmode,0,'None',
3 1,'Null',
4 2,'Row share',
5 3,'Row Exclusive',
6 4,'Share',
7 5,'Share Row Exclusive',
8 6,'Exclusive') lock_type,
9 request,ctime,block
10 from v$lock
11 where sid=158;
no rows selected.
View the Exhibit and examine the structure of the ORDERS and CUSTOMERS tables.
Evaluate the following SQL command:
SQL>SELECT o.order_id, c.cust_name, o.order_total, c.credit_limit
FROM orders o
JOIN customers c
USING (customer_id)
WHERE o.order_total > c.credit_limit
FOR UPDATE
ORDER BY o.order_id;
Which two statements are true regarding the outcome of the above query? (Choose two.)
A. It locks all the rows that satisfy the condition in the statement.
B. It locks only the columns that satisfy the condition in both the tables.
C. The locks are released only when a COMMIT or ROLLBACK is issued.
D. The locks are released after a DML statement is executed on the locked rows.
答案:AC
Evaluate the following SQL command:
SQL>SELECT o.order_id, c.cust_name, o.order_total, c.credit_limit
FROM orders o
JOIN customers c
USING (customer_id)
WHERE o.order_total > c.credit_limit
FOR UPDATE
ORDER BY o.order_id;
Which two statements are true regarding the outcome of the above query? (Choose two.)
A. It locks all the rows that satisfy the condition in the statement.
B. It locks only the columns that satisfy the condition in both the tables.
C. The locks are released only when a COMMIT or ROLLBACK is issued.
D. The locks are released after a DML statement is executed on the locked rows.
答案:AC
二、题目翻译
查看ORDERS和CUSTOMERS表的结构
评估下面的SQL命令:
关于上面查询的结果哪两句话是正确的?(选择2项)
A.锁定语句中满足条件的所有行。
B.只锁定两个表中满足条件的列。
C.只有执行COMMIT或ROLLBACK后,锁才会释放。
D.在锁定的行上执行DML语句后,锁被释放。
评估下面的SQL命令:
关于上面查询的结果哪两句话是正确的?(选择2项)
A.锁定语句中满足条件的所有行。
B.只锁定两个表中满足条件的列。
C.只有执行COMMIT或ROLLBACK后,锁才会释放。
D.在锁定的行上执行DML语句后,锁被释放。
三、题目解析
A选项正确,select .. for update语句,就是锁定select出来的所有行,以防止其它会话变更。
B选项不正确,oracle中有行锁和表锁,没有列锁,会将相关的行都锁住。
C选项,答案中是正确,但是这个说法,个人认为不是太完整。
commit和rollback后,锁的确可以被释放,
但如果说只有在commit或rollback之后才能释放锁,就有些不恰当,因为只要事务结束,锁就会被释放,而事务结束,不光只有commit和rollback,比如,还有进行DDL操作的时候,或用户正常或不正常退出的时候,都会结束事务,事务结束,锁就会被释放。
D选项不正确,在当前会话中,被锁定的行上可以做DML操作,但仍然不会释放锁,如果在其它会话中在被锁定的行上做DML操作,则会被阻塞。
B选项不正确,oracle中有行锁和表锁,没有列锁,会将相关的行都锁住。
C选项,答案中是正确,但是这个说法,个人认为不是太完整。
commit和rollback后,锁的确可以被释放,
但如果说只有在commit或rollback之后才能释放锁,就有些不恰当,因为只要事务结束,锁就会被释放,而事务结束,不光只有commit和rollback,比如,还有进行DDL操作的时候,或用户正常或不正常退出的时候,都会结束事务,事务结束,锁就会被释放。
D选项不正确,在当前会话中,被锁定的行上可以做DML操作,但仍然不会释放锁,如果在其它会话中在被锁定的行上做DML操作,则会被阻塞。
四、测试
关于C选项,测试如下,选择其中一种情况,DDL的时候,会自动提交事务,并释放锁。
会话1:
SQL> select sid from v$mystat where rownum=1;
SID
----------
158
SQL> select * from emp where ename='SCOTT' for update;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- -------------------- ------------------ ---------- ------------ ---------- ---------- ----------
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
会话2中查锁的相关信息:
SQL> set linesize 150
SQL> column o_name format a10
SQL> column lock_type format a20
SQL> column object_name format a15
SQL> select sid,type,id1,id2,
2 decode(lmode,0,'None',
3 1,'Null',
4 2,'Row share',
5 3,'Row Exclusive',
6 4,'Share',
7 5,'Share Row Exclusive',
8 6,'Exclusive') lock_type,
9 request,ctime,block
10 from v$lock
11 where sid=158;
SID TYPE ID1 ID2 LOCK_TYPE REQUEST CTIME BLOCK
---------- ---- ---------- ---------- -------------------- ---------- ---------- ----------
158 TM 58060 0 Row Exclusive 0 75 0
158 TX 65540 5023 Exclusive 0 75 0
会话1中,继续进行DDL操作:
SQL> create table test_lock(id int);
Table created.
会话2中再查锁的相关信息,就没有了,说明DDL操作也会导致事务结束,这里是自动提交了:
SQL> select sid,type,id1,id2,
2 decode(lmode,0,'None',
3 1,'Null',
4 2,'Row share',
5 3,'Row Exclusive',
6 4,'Share',
7 5,'Share Row Exclusive',
8 6,'Exclusive') lock_type,
9 request,ctime,block
10 from v$lock
11 where sid=158;
no rows selected.
0 0
- OCP-1Z0-051 第157题 事务和锁
- OCP-1Z0-051 第174题 事务的组成
- OCP-1Z0-051 第46题 约束和索引
- OCP-1Z0-051 第162题 视图和表
- OCP-1Z0-051 第10题
- OCP-1Z0-051 第54题
- OCP-1Z0-051 第60题
- OCP-1Z0-051 第171题 事务结束的条件
- OCP-1Z0-051 第172题 事务savepoint的注意事项
- OCP-1Z0-051 第173题 事务结束的条件
- OCP-1Z0-051 第8题 子查询和多表关联查询和情况
- OCP-1Z0-051-题目解析-第1题
- OCP-1Z0-051 第3题 转义字符
- OCP-1Z0-051 第4题 单行函数
- OCP-1Z0-051 第11题 sql运算顺序
- OCP-1Z0-051 第12题 别名的用法
- OCP-1Z0-051 第13题 q操作符
- OCP-1Z0-051 第14题 DISTINCT去重
- 蜗牛—职场规则,总有几条你不知道
- intellij idea 13&14 插件推荐及快速上手建议 (已更新!)
- MFC CListBox 鼠标移动到一行就显示高亮的方法代码
- 获取当前URL、controller、action
- vb.net中,如何把byte array还原成为包含中文的字符串
- OCP-1Z0-051 第157题 事务和锁
- 手把手教你ECSHOP去版权与标志
- 使用ArcGIS将Nodata区设置为0(软件操作类,非代码类)
- Codeforces 431C —— k-Tree(DP)
- 蔡莉-大数据时代下的数据质量挑战及数据质量评估
- 每天学习一个linux命令(2):cd命令
- java 像bbs.csdn一样的分页
- ubuntu下sqlite3的用法(以后会讲到wxWidgets使用sqlite3开发)
- springMvc整合Freemarker引入CSS,JS文件404的问题