declare cur_service_type cursor for select st_name,st_id from service_type;
declare continue handler for not found set stopFlag1=1;
open cur_service_type;
repeat
fetch cur_service_type into type_name,type_id;
select type_name;
until stopFlag1=1 end repeat;
close cur_service_type;service_type这个表里明明只有两条
怎么用select输出,有三条记录
最后两条是重复的?
declare continue handler for not found set stopFlag1=1;
open cur_service_type;
repeat
fetch cur_service_type into type_name,type_id;
select type_name;
until stopFlag1=1 end repeat;
close cur_service_type;service_type这个表里明明只有两条
怎么用select输出,有三条记录
最后两条是重复的?
-> begin
-> declare type_name varchar(32);
-> declare type_id int;
-> declare cur_service_type cursor for select st_name,st_id from service_type;
-> declare continue handler for not found set @stopFlag1=1;
-> open cur_service_type;
-> set @stopFlag1 = 0;
-> repeat
-> fetch cur_service_type into type_name,type_id;
-> if @stopFlag1 != 1 then
-> select type_name;
-> end if;
-> until @stopFlag1=1 end repeat;
-> close cur_service_type;
-> end;
-> //
Query OK, 0 rows affected (0.00 sec)mysql> call handlerdemo(); //
+-----------+
| type_name |
+-----------+
| aaa |
+-----------+
1 row in set (0.00 sec)+-----------+
| type_name |
+-----------+
| bbb |
+-----------+
1 row in set (0.00 sec)Query OK, 0 rows affected (0.00 sec)