在Oracle数据库中,我刚刚运行了一个查询,我得到了
删除了0行。
" 0行" DML操作在ORACLE中锁定一个表,如果是,我需要COMMIT
吗?
答案 0 :(得分:5)
答案是肯定的,是的。 Oracle会锁定已修改的行等 - 因此,如果没有行受影响,则不会发生这种情况;但Oracle也会创建一个子列外表锁,而不管是否可以修改或不修改任何行,并且它仅在COMMIT
或ROLLBACK
或同等版本上释放此类锁。 (当然,在这种情况下,你也可以ROLLBACK
- 同样的效果,因为没有行受到影响。)
在以下会话中轻松演示:
SQL> create table xx as
2 select level lvl from dual connect by level <= 5;
Table created.
SQL> select * from xx;
LVL
----------
1
2
3
4
5
SQL> select a.object_name, b.locked_mode
2 from user_objects a join v$locked_object b
3 on a.object_id = b.object_id;
no rows selected
SQL> delete from xx where lvl = 10;
0 rows deleted.
SQL> select a.object_name, b.locked_mode
2 from user_objects a join v$locked_object b
3 on a.object_id = b.object_id;
OBJECT_NAME LOCKED_MODE
--------------- -----------
XX 3
SQL> commit;
Commit complete.
SQL> select a.object_name, b.locked_mode
2 from user_objects a join v$locked_object b
3 on a.object_id = b.object_id;
no rows selected