此代码不起作用
select pagenr into @offset from pages where id = 3;
select * from table1 limit @offset*10,10;
我需要使用什么sqlcode才能使这种代码工作@H_502_10@仅使用sql!
注意
SET sql_SELECT_LIMIT = @count
不起作用,因为我主要关注的是偏移,而不是限制.
最佳答案
从MysqL 5.5规范:
The
LIMIT
clause can be used to@H_502_10@ constrain the number of rows returned@H_502_10@ by theSELECT
statement.LIMIT
takes@H_502_10@ one or two numeric arguments,which@H_502_10@ must both be nonnegative integer@H_502_10@ constants,with these exceptions:
因此,在存储过程中,以下内容将起作用:
DECLARE offset bigint
SELECT pagenr * 10 INTO offset FROM pages where id = 3;
SELECT * FROM table1 LIMIT offset,10;