Home >Database >Mysql Tutorial >mysql的limit offset后面不能跟变量,只能硬编码数字的问题_MySQL

mysql的limit offset后面不能跟变量,只能硬编码数字的问题_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 13:37:511189browse

bitsCN.com


今天在写mysql存储过程的时候遇到一问题

mysql版本呢:5.1.40

不知道高一点的版本有无此问题

如果高版本不存在此问题亲跳过

sql如下:

[sql]

 

SELECTpid,NAMESINTO_dp_id,_dp_namesFROMdepartmentLIMIT1OFFSET_dp_count;

_dp_count是我声明的一变量

 

执行的时候报错...

 

mysql的limit offset后面不能跟变量,只能硬编码数字的问题_MySQL

 

[html]

错误码: 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 '_dp_count;
 

原来 mysql的 limit 和 offset后面都不能跟变量  

 

解决方法是用 CONCAT 把sql拼起来

 

然后PREPARE再EXECUTE 就OK了


mysql的limit offset后面不能跟变量,只能硬编码数字的问题_MySQL

 

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn