MySQL -Dynamic SQL无法识别错误

时间:2015-10-20 12:34:59

标签: mysql dynamic-sql

CREATE DEFINER=`root`@`localhost` PROCEDURE `WhileLoopProc`()

BEGIN

DECLARE x INT;

SET x = 1;

loop1:  WHILE x  <= 213 DO

        SET @s = CONCAT('SELECT Units, NAV FROM jbequity.nav WHERE ClientID =', x ,'ORDER BY Date LIMIT 1');

   PREPARE stmt FROM @s;

     EXECUTE stmt;

   DEALLOCATE PREPARE stmt;

 SET  x = x + 1; 

    END WHILE loop1 ;

END

1 个答案:

答案 0 :(得分:0)

尝试一次删除ORDER BY DateLIMIT 1一个以查看导致错误的部分,然后google那个无法学习如何使用它的部分。

修改

我怀疑问题是你错过了ORDER BY

前面的空格