Mysql存储过程中的未知系统变量“no_more_data”

时间:2011-04-29 02:54:46

标签: mysql stored-procedures mysql-error-1193

我是新用的mysql存储过程。有一个我无法解决的错误 这是我的代码

DELIMITER $$

CREATE PROCEDURE `bankdb`.`charge` () 
BEGIN
DECLARE idcust_val INT;
DECLARE balance_val FLOAT;
DECLARE productCd_val VARCHAR(10);

DECLARE loop_cntr INT DEFAULT 0;
DECLARE num_rows INT DEFAULT 0;

DECLARE col_cur CURSOR FOR
select c.cust_id, c.balance, c.product_cd
from account c;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_rows = TRUE;

OPEN col_cur;
select FOUND_ROWS() into num_rows;

read_loop: LOOP
FETCH col_cur INTO idcust_val, balance_val, productCd_val;

IF no_more_rows THEN
close col_cur;
leave read_loop;
END IF;

IF productCd_val == 'SAV' || productCd_val == 'CD' THEN
    IF balance_val == 2000 THEN
          balance_val = balance_val-10;
          UPDATE account SET avail_balance = balance_val
          WHERE account_id =idcust_val;
    END IF;
END IF;

IF productCd_val == 'CHK' || productCd_val == 'SAV' || productCd_val == 'MM'
|| productCd_val == 'CD' THEN
  balance_val = balance_val + (balance_val*0,05);
  UPDATE account SET avail_balance = balance_val
  WHERE account_id =idcust_val;
ELSE
  balance_val = balance_val - (balance_val*0,1);
  UPDATE account SET avail_balance = balance_val
  WHERE account_id =idcust_val;
END IF;
 SET loop_cntr = loop_cntr + 1;
END LOOP;
END $$

DELIMITER ;

当我执行它时,mysql查询浏览器会显示如下错误:

  

脚本行:3未知系统变量'no_more_rows'

请帮助我!!

1 个答案:

答案 0 :(得分:2)

  1. 必须延迟变量no_more_rows,在程序正文的开头写下一行。

    DECLARE no_more_rows INT DEFAULT 0;

  2. 等于运算符是'='

    如果productCd_val =='SAV'等应该是IF productCd_val ='SAV'

  3. 使用SET命令分配值,例如 -

    SET balance_val = balance_val - 10;