DECLARE rs CURSOR FOR SELECT * from LQL170;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET Done = 1;
我在存储过程中定义游标,一保存,就是 DECLARE rs CURSOR FOR SELECT * from LQL170;说附近有语法错误,刚需写的 请大神多多指教
DELIMITER $$
CREATE PROCEDURE testa()
BEGIN
DECLARE sqlStr1 VARCHAR(2000);
DECLARE i INT(10) DEFAULT 0;
DECLARE k INT(10) DEFAULT 0;
DECLARE Done INT DEFAULT 0;
DECLARE seltable VARCHAR(2000);
DECLARE _mon VARCHAR(20);
DECLARE _bh VARCHAR(20);
DECLARE _xm VARCHAR(100);
DECLARE _bm VARCHAR(20);
DECLARE _gw VARCHAR(20);
DECLARE _jj VARCHAR(20);
DECLARE rs CURSOR FOR SELECT SYBH,XM,BMBH,GW FROM LQL170;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET Done = 1;
DROP TABLE IF EXISTS tab_Ltext;
SET seltable='';hindi sms
sms
SET sqlStr1='';
SET @sqlStr1 = CONCAT('CREATE TABLE tab_Ltext(month1 VARCHAR(20), bh VARCHAR(10),xm VARCHAR(100),bm VARCHAR(20),gw VARCHAR(100),jj VARCHAR(10))');
PREPARE s FROM @sqlStr1;
EXECUTE s;
SELECT COUNT(*)INTO i FROM LQL170;
SET @seltable = CONCAT('select',' SYBH,XM,BMBH,GW,SCQF,TSRQ from LQL170 ');
-- INSERT INTO tab_Ltext(month1,bh,xm,bm,gw,jj)VALUES('2012','','','','','');
PREPARE s1 FROM @seltable;
EXECUTE s1;
SELECT COUNT(*) INTO i FROM LQL170;
OPEN rs;
REPEAT
FETCH NEXT FROM rs INTO _bh,_xm ,_bm,_gw ;
INSERT INTO tab_Ltext(month1,bh,xm,bm,gw,jj) VALUES ('2012/10',_bh,_xm,_bm,_gw,'1000');
SET i =i - 1;
UNTIL i =0 END REPEAT;
CLOSE rs;
SELECT * FROM tab_Ltext;
-- SELECT i ;
END$$
DELIMITER ;