Oracle游标之select for update和where current of 语句
2013-06-27 10:57
387 查看
转载http://hanjiangduqiao.blog.163.com/blog/static/613105442011431111153601
使用select for update 语句可以使用行锁锁定你要更改的记录.当遇到下一个commit和rollback语句时会被释放.
The
Select For Update statement allows you to lock the records in the cursor result set. You are not required to make changes to the records in order to use this statement. The record locks are released when the next commit or rollback statement
is issued.
语法如下:The syntax for the
Select For Update is:
CURSOR cursor_name
IS
select_statement
FOR UPDATE [of column_list] [NOWAIT];
当你要使用游标进行更新和删除操作时,则需要使用where current of 语句,这个是标示出当前游标的位置.
If you plan on updating or deleting records that have been referenced by a
select for update statement, you can use the Where Current Of statement.
语法如下:The syntax for the Where Current Of statement is either:
UPDATE table_name
SET set_clause
WHERE CURRENT OF cursor_name;
OR
DELETE FROM table_name
WHERE CURRENT OF cursor_name;
在这时的例子中我采用上面所建的test表来试验.
2.1 更新.
SQL> DECLARE
2 CURSOR test_cur IS SELECT * FROM test
3 FOR UPDATE OF sal;
4 BEGIN
5 FOR test_rec IN test_cur LOOP
6 UPDATE test
7 SET sal = test_rec.sal +1
8 WHERE CURRENT OF test_cur;
9 END LOOP;
10 COMMIT;
11 END;
12 /
PL/SQL 过程已成功完成。
2.2 删除.
SQL> DECLARE
2 CURSOR test_cur IS select * from test for update;
3 BEGIN
4 FOR test_rec IN test_cur LOOP
5 DELETE FROM test WHERE CURRENT OF test_cur;
6 END LOOP;
7 END;
8 /
PL/SQL 过程已成功完成。
文中的游标只是简单的使用,在记录到pl/sql详细编程的时候会再讲到时会结合oracle的执行计划并一起讨论它们的执行效率.
注:文中的英文注解部分出自:http://www.techonthenet.com/oracle/cursors/current_of.php
/
使用select for update 语句可以使用行锁锁定你要更改的记录.当遇到下一个commit和rollback语句时会被释放.
The
Select For Update statement allows you to lock the records in the cursor result set. You are not required to make changes to the records in order to use this statement. The record locks are released when the next commit or rollback statement
is issued.
语法如下:The syntax for the
Select For Update is:
CURSOR cursor_name
IS
select_statement
FOR UPDATE [of column_list] [NOWAIT];
当你要使用游标进行更新和删除操作时,则需要使用where current of 语句,这个是标示出当前游标的位置.
If you plan on updating or deleting records that have been referenced by a
select for update statement, you can use the Where Current Of statement.
语法如下:The syntax for the Where Current Of statement is either:
UPDATE table_name
SET set_clause
WHERE CURRENT OF cursor_name;
OR
DELETE FROM table_name
WHERE CURRENT OF cursor_name;
在这时的例子中我采用上面所建的test表来试验.
2.1 更新.
SQL> DECLARE
2 CURSOR test_cur IS SELECT * FROM test
3 FOR UPDATE OF sal;
4 BEGIN
5 FOR test_rec IN test_cur LOOP
6 UPDATE test
7 SET sal = test_rec.sal +1
8 WHERE CURRENT OF test_cur;
9 END LOOP;
10 COMMIT;
11 END;
12 /
PL/SQL 过程已成功完成。
2.2 删除.
SQL> DECLARE
2 CURSOR test_cur IS select * from test for update;
3 BEGIN
4 FOR test_rec IN test_cur LOOP
5 DELETE FROM test WHERE CURRENT OF test_cur;
6 END LOOP;
7 END;
8 /
PL/SQL 过程已成功完成。
文中的游标只是简单的使用,在记录到pl/sql详细编程的时候会再讲到时会结合oracle的执行计划并一起讨论它们的执行效率.
注:文中的英文注解部分出自:http://www.techonthenet.com/oracle/cursors/current_of.php
/
相关文章推荐
- PLSQL条件语句完成员工加薪功能(记录类型+游标case when+if+for update+where current of)
- oracle 隐式游标,显示游标,游标循环,动态SELECT语句和动态游标、异常等
- Oracle select --lnnvl用于某个语句的where子句中的条件
- oracle 隐式游标,显示游标,游标循环,动态SELECT语句和动态游标,异常处理,自定义异常
- oracle 隐式游标,显示游标,游标循环,动态SELECT语句和动态游标,异常处理,自定义异常
- oracle 隐式游标,显示游标,游标循环,动态SELECT语句和动态游标,异常处理,自定义异常
- oracle 隐式游标,显示游标,游标循环,动态SELECT语句和动态游标,异常处理,自定义异常,
- Oracle/PLSQL: WHERE CURRENT OF Statement
- oracle 隐式游标,显示游标,游标循环,动态SELECT语句和动态游标,异常处理,自定义异常,
- oracle 隐式 游标 显示 循环 动态 select 语句 游标 异常 处理 自定义 游标的概念
- ORACLE中SELECT语句的where中引用列别名报错
- oracle查询语句中select from where group by having order by的解释与应用
- oracle 隐式游标,显示游标,游标循环,动态SELECT语句和动态游标,异常处理,自定义异常,
- oracle 隐式游标,显示游标,游标循环,动态SELECT语句和动态游标,异常处理,自定义异常,
- where current of语句
- Oracle/PLSQL: WHERE CURRENT OF Statement
- Oracle-18-select语句初步&SQL中用算术表达式&别名的使用&连接运算符%distinct&where子句
- oracle 隐式游标,显示游标,游标循环,动态SELECT语句和动态游标、异常等
- oracle 隐式游标,显示游标,游标循环,动态SELECT语句和动态游标,异常处理,自定义异常【转载】
- oracle 隐式游标,显示游标,游标循环,动态SELECT语句和动态游标,异常处理,自定义异常【转载】