Posted on 2010-03-17 23:55
Prayer 閱讀(2085)
評(píng)論(0) 編輯 收藏 引用 所屬分類:
DB2
注意commit和rollback
使用游標(biāo)時(shí)要特別注意如果沒(méi)有加with hold 選項(xiàng),在Commit和Rollback時(shí),該游標(biāo)將被關(guān)閉。Commit 和Rollback有很多東西要注意。特別小心
游標(biāo)的兩種定義方式
一種為
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;
這種方式使用起來(lái)比較復(fù)雜,但也比較靈活。特別是可以使用with hold 選項(xiàng)。如果循環(huán)內(nèi)有commit或rollback 而要保持該cursor不被關(guān)閉,只能使用這種方式。