MYSQL:未声明的变量

时间:2014-06-10 13:07:32

标签: mysql stored-procedures

我有两个存储过程第一个带静态的参数,效果很好 但当我,但动态参数,它给我一个错误未声明的变量:limitvar
1 /程序

`DELIMITER $$

DROP PROCEDURE IF EXISTS `gestprospects`.`recClientsFiltre` $$
CREATE  PROCEDURE `recClientsFiltre`(IN params text, in limitvar int , in offsetvar int )

BEGIN
SET @query := concat(concat("SELECT ... WHERE CONCAT(clients.id,'-') in (",params),") limit 10,10");
  PREPARE stmt FROM @query ;
  EXECUTE stmt  ;
  DEALLOCATE PREPARE stmt;

END  $$

DELIMITER ;`

2 /程序

 DELIMITER $$

DROP PROCEDURE IF EXISTS `gestprospects`.`recClientsFiltre` $$
CREATE  PROCEDURE `recClientsFiltre`(IN params text, in limitvar int , in offsetvar int )

BEGIN
SET @query := concat(concat("SELECT ... WHERE CONCAT(clients.id,'-') in (",params),") limit limitvar,offsetvar");
  PREPARE stmt FROM @query ;
  EXECUTE stmt  ;
  DEALLOCATE PREPARE stmt;

END  $$

DELIMITER ;

感谢您的回复

1 个答案:

答案 0 :(得分:0)

您在动态查询中包含了小字符串limitvaroffsetvar,而您想要包含它们的值。

@query := CONCAT(
    "SELECT ... WHERE CONCAT(clients.id,'-') IN (", params,")",
    " LIMIT ", limitvar, ", ", offsetvar);

请注意CONCAT()的一次通话{/ 3}} {/ 3}}