存储过程查询错误

Error in stored procedure query

我在存储过程中遇到以下错误:

DELIMITER $$
DROP PROCEDURE IF EXISTS `comm_pay_intro`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `comm_pay_intro`(IN `id` VARCHAR(20),IN 
`comm_type` VARCHAR(50))
BEGIN
DECLARE i INTEGER;
 DECLARE userid varchar(20);
 DECLARE rateid int(10);
 DECLARE levels int(1);
 DECLARE idx INTEGER;
DECLARE curs1 CURSOR FOR (SELECT `id` , `user_id`
 FROM `temp_table` order by `id`);
OPEN curs1;
FETCH curs1 INTO idx,userid;
Select `level_id` into rateid , `levels` into levels FROM `user_levels`
 INNER JOIN `commission_type` ON `type_id`=`Commission_Type` WHERE 
`Commission_Type`=comm_type and `levels`=idx
order by `levels`;
   insert into user_commission(rate_id, user_id) 
VALUES(rateid,userid); 
CLOSE curs1;
END$$
DELIMITER ;

错误:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'into levels FROM user_levels INNER JOIN commission_type ON type_id=`Comm' at line 13

更改 SELECT .. INTO 语句,如下所示。另外,您的变量名 levels 与列名相同;这可能会导致问题。不要这样命名你的变量。

Select `level_id`, `levels` into rateid , levels FROM `user_levels`

有关相同内容的更多信息,请参阅 Documentation

喜欢这个

 Select `level_id`,`levels` into rateid  levels FROM `user_levels`