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 '000000' 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;
The cursor definition statement must be placed behind the definition of other variables. Otherwise, an error occurs. For example, if the positions of rows 8th and 9th are changed, an error is returned.