1 DELIMITER $$
2
3 DROP PROCEDURE IF EXISTS `jf`.`insert2`$$
4
5 CREATE PROCEDURE `insert2`(in yhbh varchar(50),out bjbh varchar(50))
6 BEGIN
7 declare tempbjbh varchar(50) default 0;
8 declare done int default 0;
9 declare cur1 CURSOR FOR select ffgl.c_bjbh from ffgl,dj_info where ffgl.c_yhbh='U01010101' and ffgl.n_fflx=dj_info.n_fflx order by ffgl.c_bjbh asc;
10
11 declare CONTINUE HANDLER FOR SQLSTATE '02000' SET done=1;
12 open cur1;
13 Repeat
14 fetch cur1 into tempbjbh;
15 if not done then
16 set tempbjbh=concat(tempbjbh,"/");
17 set bjbh=concat(bjbh,tempbjbh);
18 end if;
19 until done end repeat;
20 close cur1;
21 select bjbh;
22 END$$
23
24 DELIMITER ;
游标定义语句一定要放到其他变量的定义后边,否则会出错,如第8行和第9行换一下位置,就会报错。