预处理嵌套游标无效!!!大神请进
use st;
DELIMITER $$
CREATE PROCEDURE 2in1()
begin
declare bm char(8);
declare found2 boolean default true;
declare bm_ cursor for select table_name from information_schema.tables where table_schema='st' limit 1,15000;
declare continue handler for not found set found2=false;
open bm_;
while found2 do
fetch bm_ into bm;
if found=true then
begin
declare rq_ date;
declare found boolean default true;
# declare rq_bcf cursor for select distinct(rq) from bm;
SET @STMT=CONCAT('declare rq_bcf cursor for select distinct(rq) from ',bm,';');
PREPARE STMT FROM @STMT;
EXECUTE STMT;
# DEALLOCATE PREPARE stmt;
open rq_bcf;
while found do
fetch rq_bcf into rq_;
end while;
close rq_bcf;
end;
end if;
end while;
close bm_;
end$$
delimiter ;
运行提示:
ERROR 1324 (42000): Undefined CURSOR: rq_bcf
真是没有办法了,请教再请教。
------解决方案--------------------
declare rq_bcf cursor for select * from newtt;
......
set @asql=concat('create table newttt as select distinct(rq) from ',bm);
PREPARE STMT FROM @asql;
EXECUTE STMT;
.....
------解决方案--------------------游标不支持,你需要另想办法,比如把符合条件的某表中的记录插入到另一个固定表名中,然后使用游标。
------解决方案--------------------至少目前版本的MYSQL不支持动态的CURSOR