select * from test limit 3, 20;
表示每页显示20个, 第3页.这种写法不能通过PreparedStatement执行, 因为它是编译过的, 存储过程同理.所以这样写不会成功:
create procedure pager (in pno int, in psize int)
begin
declare pp int default 0;
set pp = (pno - 1) * psize;
select * from pager limit pp, psize;
end
应该算是mysql的bug.
有个折衷的办法:
create procedure pager (in _pno int, in _psize int)
begin
prepare stmt from "select * from test limit ?,?";
set @pno = (_pno - 1) * _psize;
set @psize = _psize;
execute stmt using @pno, @psize;
end
link, link
No comments:
Post a Comment