这个存储过程为什么创建不了 ?
-
SQL code
create PROCEDURE find_address_by_page(in startid INT , in querycount int ) BEGIN -- select * from address wehre a_id = startid ; //如果用这条语句都可以创建过程 成功 select * from address limit startid , querycount; -- 这条语句怎么不能成功呢? end;
错误
[Err] 1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘startid , querycount;
end’ at line 4
select * from address limit startid , querycount;
LIMIT后必须是常数,不能是变量。
如果需要使用则可以使用 PREPARE 方式。
引用
mysql> PREPARE stmt1 FROM ‘SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse’;
mysql> SET @a = 3;
mysql> SET @b = 4;
mysql> EXECUTE stmt1 USING @a, @b;
+————+
| hypotenuse |
+————+
| 5 |
+————+
mysql> DEALLOCATE PREPARE stmt1;
语法错误,limit是用来做限制的!
limit 不能用变量,这样不确定。
你的startid,querycount是变量而不是常量。
select * from address limit startid , querycount