这个存储过程错哪了
这个存储过程哪里错了?
用Mysql5.6.5里运行是正确的,现在用5.1,就不对了。。。该怎么改呢?
drop procedure if exists usp_add_comment;
CREATE PROCEDURE usp_add_comment(
v_gameid int,
v_commenter varchar(20),
v_content varchar(255),
v_startRow int,
v_endRow int,
out v_count int
)
begin
set v_startRow=v_startRow-1;
insert into t_comment(GameId,Commenter,Content) values(v_gameid,v_commenter,v_content);
commit;
select count(1) into v_count from t_comment where GameId=v_gameid;
select Commenter,CommentTime,Content from t_comment where GameId=v_gameid order by CommentTime desc limit
--这行出错,如果直接写上数字的话,不会出错的。
v_startRow,v_endRow;
end;
------解决方案--------------------
limit 后面不能用变量.
用prepare 吧
http://topic.****.net/u/20120903/14/9c8d1431-5454-43a2-b77d-882d2770e303.html?r=79578973
------解决方案--------------------
MYSQL中 limit后的参数不允许为变量,只能是常数。
------解决方案--------------------
用动态语句来完成
SET @ASQL=CONCAT('SQL语句 limit ',数字);
prepare stml from @asql;
execute stml;
------解决方案--------------------
------解决方案--------------------
5.1版本里面不允许limit 后面带变量,5.5之后改进了,支持变量。
5.1只能通过prepare 来实现。
用Mysql5.6.5里运行是正确的,现在用5.1,就不对了。。。该怎么改呢?
drop procedure if exists usp_add_comment;
CREATE PROCEDURE usp_add_comment(
v_gameid int,
v_commenter varchar(20),
v_content varchar(255),
v_startRow int,
v_endRow int,
out v_count int
)
begin
set v_startRow=v_startRow-1;
insert into t_comment(GameId,Commenter,Content) values(v_gameid,v_commenter,v_content);
commit;
select count(1) into v_count from t_comment where GameId=v_gameid;
select Commenter,CommentTime,Content from t_comment where GameId=v_gameid order by CommentTime desc limit
--这行出错,如果直接写上数字的话,不会出错的。
v_startRow,v_endRow;
end;
------解决方案--------------------
limit 后面不能用变量.
用prepare 吧
http://topic.****.net/u/20120903/14/9c8d1431-5454-43a2-b77d-882d2770e303.html?r=79578973
------解决方案--------------------
MYSQL中 limit后的参数不允许为变量,只能是常数。
------解决方案--------------------
用动态语句来完成
SET @ASQL=CONCAT('SQL语句 limit ',数字);
prepare stml from @asql;
execute stml;
------解决方案--------------------
------解决方案--------------------
5.1版本里面不允许limit 后面带变量,5.5之后改进了,支持变量。
5.1只能通过prepare 来实现。