delimiter $$
drop procedure if exists `proc_cur`$$
create procedure `proc_cur`()
begin
declare done int default 0;
declare myid int;
declare cur1 cursor for select id from aa;
declare continue handler for sqlstate '02000' set done = 1;
open cur1;
repeat
fetch cur1 into myid;
...until done end repeat;
close cur1;
end$$
delimiter ;
注意問題:
1.定義要連在一起,否則要出錯
declare cur1 cursor for select id from aa;
declare continue handler for sqlstate '02000' set done = 1;
2.done的值需要初始化,在迴圈中不需要改它的值
mysql 遍歷游標 處理
1,建立儲存過程 delimiter use test drop procedure if exists proc style10 t use test create procedure test.proc style10 t begin declare v cmp id int declare v...
MySQL 游標 游標
游標cursor是用來儲存查詢結果集的 資料型別 在儲存過程和函式中可以使用游標對結果集進行迴圈的處理。游標的使用包括游標的宣告 open fetch 和 close,其語法分別如下 宣告游標 declare cursor name cursor for select statement open ...
mysql游標型別 MySQL 游標
drop procedure if exists processorders create procedure processorders begin declare done boolean default 0 declare a int declare b varchar 20 定義游標遍歷時,...