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