mysql 语句中带变量

select  CONCAT("old_",@a:=@a+1)  aaa from sss




以下内容转载

在项目开发过程中用到hibernate的createSQLQuery,报如下错误:
org.hibernate.QueryException: Space is not allowed after parameter prefix ':' [select * from (select a.*,@X:=IFNULL(@X,0)+1 AS rownum from meetingTask a inner join meeting b on b.meetingId = a.meetingId and b.convener = 'null' where a.meetingId = 'undefined' AND  1=1) b  where b.rownum between 1 and 10]

解决方案是:@X:=IFNULL(@X,0)+1改成@X\\:=IFNULL(@X,0)+1,也就是在":"号前加上"\\",把冒号给注释一下,让hibernate知道是mysql的占位标记

你可能感兴趣的:(mysql)