Law*_*nce 9 database oracle cursors
关于游标的快速问题(特别是Oracle游标).
假设我有一个名为"my_table"的表,它有两列,一个ID和一个名字.有数百万行,但name列始终是字符串'test'.
然后我运行这个PL/SQL脚本:
declare
cursor cur is
select t.id, t.name
from my_table t
order by 1;
begin
for cur_row in cur loop
if (cur_row.name = 'test') then
dbms_output.put_line('everything is fine!');
else
dbms_output.put_line('error error error!!!!!');
exit;
end if;
end loop;
end;
/
Run Code Online (Sandbox Code Playgroud)
如果我在运行时运行此SQL:
update my_table
set name = 'error'
where id = <max id>;
commit;
Run Code Online (Sandbox Code Playgroud)
PL/SQL块中的光标是否会接收该更改并打印出"错误错误错误"并退出?或者它根本不会接受更改......或者它是否会允许更新my_table?
谢谢!
Sea*_*ins 13
游标有效地运行SELECT,然后让您迭代结果集,该结果集保存在DB状态的快照中.因为已经获取了结果集,所以它不会受UPDATE语句的影响.(否则每次处理光标时都需要重新运行查询!)
看到:
http://www.techonthenet.com/oracle/cursors/declare.php