且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在limit语句中使用用户定义的变量?

更新时间:2022-11-09 22:58:38

您不能将用户定义的变量与LIMIT一起使用.

You cannot use the user defined variables with LIMIT.

MySQL Doc说在大多数情况下,用户变量可能会用到 允许使用表达式.当前不包括上下文 明确需要文字值(例如在LIMIT子句中) SELECT语句或LOAD DATA的IGNORE N LINES子句 声明"

MySQL Doc says "User variables may be used in most contexts where expressions are permitted. This does not currently include contexts that explicitly require a literal value, such as in the LIMIT clause of a SELECT statement, or the IGNORE N LINES clause of a LOAD DATA statement"

但是您可以使用'用户定义函数''

But you can achieve similar functionality using 'user defined function' or 'stored procedure' or 'plain SQL by calculating @rowid and using it in the where clause'.