Heim >Datenbank >MySQL-Tutorial >mysql的limit offset后面不能跟变量,只能硬编码数字的问题_MySQL

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 13:37:511187Durchsuche

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
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn