Posted on 2010-03-17 23:55
Prayer 閱讀(2086)
評論(0) 編輯 收藏 引用 所屬分類:
DB2
注意commit和rollback
使用游標時要特別注意如果沒有加with hold 選項,在Commit和Rollback時,該游標將被關閉。Commit 和Rollback有很多東西要注意。特別小心
游標的兩種定義方式
一種為
declare continue handler for not found
begin
set v_notfound = 1;
end;
declare cursor1 cursor with hold for select market_code from tb_market_code for update;
open cursor1;
set v_notfound=0;
fetch cursor1 into v_market_code;
while v_notfound=0 Do
--work
set v_notfound=0;
fetch cursor1 into v_market_code;
end while;
close cursor1;
這種方式使用起來比較復雜,但也比較靈活。特別是可以使用with hold 選項。如果循環內有commit或rollback 而要保持該cursor不被關閉,只能使用這種方式。