关于mysql游标的一个例子

来源:互联网 发布:网络社群营销 编辑:程序博客网 时间:2024/06/11 18:04

declare fetchSeqOk boolean; ## define the flag for loop judgement
declare _seqname varchar(50); ## define the varient for store the data
declare _value bigint(20);
declare fetchSeqCursor cursor for select seqname, value from sys_sequence;## define the cursor
declare continue handler for NOT FOUND set fetchSeqOk = true; ## define the continue handler for not found flag
set fetchSeqOk = false;


open fetchSeqCursor;
fetchSeqLoop:Loop
if fetchSeqOk then
leave fetchSeqLoop;
else
fetch cursor into _seqname, _value;
begin

declare fetchSeqOk boolean default 'inner';
declare cursor2 cursor for select .... from ...;## define the cursor
declare continue handler for NOT FOUND set fetchSeqOk = true; ## define the continue handler for not
set fetchSeqOk = false;
open cursor2;
fetchloop2 loop
if fetchSeqOk then
else

end if;

end loop;
close cursor2;
end;
end if;

end Loop;
close fetchSeqCursor;

 

原创粉丝点击