[pl sql] where current of
使用select for update 的時候的幾個問題
1,使用顯示靜態遊標
eg:
create table tb_test_1 (id number,
name varchar2(20));
insert into tb_test_1 (id, name) values (1, 'name');
declare
my_test test.tb_test_1%rowtype;
cursor cs is
select * from tb_test_1 for update;
begin
for css in cs loop
my_test.id := css.id;
my_test.name := css.name || 's';
update tb_test_1 a
set a.id = my_test.id, a.name = my_test.name
where current of cs;
end loop;
commit;
end;
若:
declare
my_test test.tb_test_1%rowtype;
type cs is ref cursor;
css cs;
begin
open css for
select * from tb_test_1 for update;
loop
fetch css into my_test;
exit when css%notfound;
update tb_test_1 a
set a.id = my_test.id, a.name = my_test.name||'s'
where current of css;
end loop;
commit;
end;
則ora-06550
2,注意loop內不能commit
eg:
insert into tb_test_1 (id, name) values (2, 'name2');
declare
my_test test.tb_test_1%rowtype;
cursor cs is
select * from tb_test_1 for update;
begin
for css in cs loop
my_test.id := css.id;
my_test.name := css.name || 's';
update tb_test_1 a
set a.id = my_test.id, a.name = my_test.name
where current of cs;
commit;
end loop;
commit;
end;
則:ora-01002
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16179598/viewspace-531591/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- PL/SQLSQL
- SQL Where in list 問題SQL
- SQL&PL/SQL (轉)SQL
- PL/SQL 宣告SQL
- PL/SQL cursorSQL
- PL/SQL打包SQL
- PL/SQL DEVSQLdev
- Oracle PL/SQLOracleSQL
- 使用PL/Scope分析PL/SQL程式碼SQL
- PLSQL Language Reference-PL/SQL概覽-PL/SQL架構SQL架構
- [PL/SQL]10g PL/SQL學習筆記(一)SQL筆記
- [PL/SQL]10g PL/SQL學習筆記(二)SQL筆記
- [PL/SQL]10g PL/SQL學習筆記(三)SQL筆記
- PL/SQL 迴圈SQL
- PL/SQL 遊標SQL
- PL/SQL 運算子SQL
- PL/SQL 條件SQL
- pl/sql to_dateSQL
- PL/SQL 基礎SQL
- Oracle PL/SQL INDICESOracleSQL
- PL/SQl Developer使用SQLDeveloper
- pl/sql陣列SQL陣列
- pl/sql練習SQL
- oracle PL/SQL示例OracleSQL
- 淺談pl/sqlSQL
- PL/SQL 索引表SQL索引
- pl/sql 練習SQL
- pl/sql功能特性SQL
- PL/SQL Developer 使用SQLDeveloper
- PL/SQL小結SQL
- steven's pl/sqlSQL
- PL/SQL入門SQL
- PL/SQL 設定SQL
- PLSQL Language Reference-PL/SQL概覽-PL/SQL的優點SQL
- Oracle PL/SQL編寫PL/SQL程式碼的注意事項OracleSQL
- ONLine SQL and PL/SQL FormatterSQLORM
- PL/SQL執行動態SQLSQL
- SQL中where和on的區別SQL