日期:2014-05-18  浏览次数:20492 次

Mysql 中的declare
我想通过一个循环输入一条select语句中的所有记录
declare i int;
set i=150;
while i<=200 DO
BEGIN
select dutyid from hst_cashserial where dutyid=@i;
set i=i++;
end;


运行后报错:
[SQL] declare i int;
[Err] 1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'declare i int' at line 1

MYSQL的版本是4.0 网上翻了翻,语法应该没错误呀、难道是MYSQL4.0 不支持?吐血

------解决方案--------------------
建议去MYSQL问问
------解决方案--------------------
定义变量@i不是i
SQL code

declare i int;--改成declare @i int
set i=150;--改成@i=150
while i<=200 DO --改成while @i<200 do
BEGIN
select dutyid from hst_cashserial where dutyid=@i;
set i=i++; --改成set @i=@i+1
end;