存储过程查询

时间:2016-12-08 14:08:14

标签: mysql stored-procedures mariadb

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

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 ;

错误:

  

您的SQL语法有错误;检查与您的MariaDB服务器版本对应的手册,以便在#{1}}级别附近使用正确的语法   INNER JOIN user_levels ON commission_type =`Comm'在第13行

2 个答案:

答案 0 :(得分:1)

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

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

有关详细信息,请参阅Documentation

答案 1 :(得分:0)

喜欢这个

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