我希望此过程将内容从lib_booksdist复制到lib_books,但始终显示此错误:
delimiter //
create or replace procedure add_batch()
begin
select count into @c from `lib_booksdist` group by book_insertedon having book_insertedon= max(book_insertedon);
set @i=0;
while i < c do
INSERT INTO `lib_books` (book_name, book_dept, book_sub, book_insertedby, book_insertedon)
select book_name, book_dept, book_sub, book_insertedby, book_insertedon from `lib_booksdist`
group by book_name
having book_insertedon=max(book_insertedon);
set @i=i+1;
end while;
end;//
delimiter ;
上面的代码在MySQL(MariaDB)中生成此错误。
ERROR 1054 (42S22): Unknown column 'i' in 'field list'
答案 0 :(得分:0)
所以我发现问题代码有2个问题
while i < c
)应该是while @i < @c
set @i=i+1
)应该是set @i=@i+1
感谢所有评论,帮助我弄清楚了