读书人

Mysql 中的declare,该怎么解决

发布时间: 2012-06-03 16:59:40 作者: rapoo

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 intset i=150;--改成@i=150while i<=200 DO --改成while @i<200 doBEGINselect dutyid from hst_cashserial where dutyid=@i;set i=i++; --改成set @i=@i+1end; 

读书人网 >SQL Server

热点推荐