一个存储过程中FETCH_STATUS问题????
[code=SQL][/code]delimiter //
drop FUNCTION if exists tests//
create FUNCTION tests() RETURNS varchar(30)
BEGIN
declare st1 VARCHAR(30) default '0';
declare st2 VARCHAR(30) default '0';
declare st3 VARCHAR(30) default '0';
declare cursor1 cursor for select address,city from persons;
FETCH next from cursor1 into st2,st3;
while @@FETCH_STATUS = 0 DO
SET st1 = CONCAT (st2,st3);
end while;
close cursor1;
RETURN st1;
END //
deallocate cursor1;
delimiter ;
#运行提示unknown system variable FETCH_STATUS
#以上是mysql语句!
------解决方案--------------------
楼主可能参考一下MYSQL官方免费手册中的例子如下。
CREATE PROCEDURE curdemo()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE a CHAR(16);
DECLARE b,c INT;
DECLARE cur1 CURSOR FOR SELECT id,data FROM test.t1;
DECLARE cur2 CURSOR FOR SELECT i FROM test.t2;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur1;
OPEN cur2;
REPEAT
FETCH cur1 INTO a, b;
FETCH cur2 INTO c;
IF NOT done THEN
IF b < c THEN
INSERT INTO test.t3 VALUES (a,b);
ELSE
INSERT INTO test.t3 VALUES (a,c);
END IF;
END IF;
UNTIL done END REPEAT;
CLOSE cur1;
CLOSE cur2;
END