we are using below program,
we want to create cursor with dynamic argument passed in procedure
in this program we create cursor with inrl (inrl is parameter passed in procedure)
DROP PROCEDURE IF EXISTS getrolln;
DELIMITER //
CREATE PROCEDURE getrolln(in inrl varchar(30), in inrol int(10) )
begin
DECLARE done INT DEFAULT 0;
DECLARE xtroll int(10) default 2000;
DECLARE xformno int(10) default 0;
DECLARE a varchar(100) default 0;
DECLARE stroll int(10) default 0;
DECLARE xtable varchar(100) default 0;
set @xtable = inrl;
set @a=concat("select FORMNO from ", @xtable ," order by ATTEMPT,NAME,FNAME,MNAME");
DECLARE hs CURSOR FOR @a;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
open hs;
repeat
FETCH hs into xformno;
set xtroll = xtroll + 1;
set @a=concat("update arl set ROLLNO = ",xtroll," where FORMNO = ",xformno);
PREPARE stmt FROM @a;
execute stmt;
UNTIL done END REPEAT;
close hs;
end //
DELIMITER ;
we want to create cursor with dynamic argument passed in procedure
in this program we create cursor with inrl (inrl is parameter passed in procedure)
DROP PROCEDURE IF EXISTS getrolln;
DELIMITER //
CREATE PROCEDURE getrolln(in inrl varchar(30), in inrol int(10) )
begin
DECLARE done INT DEFAULT 0;
DECLARE xtroll int(10) default 2000;
DECLARE xformno int(10) default 0;
DECLARE a varchar(100) default 0;
DECLARE stroll int(10) default 0;
DECLARE xtable varchar(100) default 0;
set @xtable = inrl;
set @a=concat("select FORMNO from ", @xtable ," order by ATTEMPT,NAME,FNAME,MNAME");
DECLARE hs CURSOR FOR @a;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
open hs;
repeat
FETCH hs into xformno;
set xtroll = xtroll + 1;
set @a=concat("update arl set ROLLNO = ",xtroll," where FORMNO = ",xformno);
PREPARE stmt FROM @a;
execute stmt;
UNTIL done END REPEAT;
close hs;
end //
DELIMITER ;