错误1054(42S22):“字段列表”中的未知列“ i”

时间:2018-07-02 14:05:05

标签: mysql mariadb

我希望此过程将内容从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'

1 个答案:

答案 0 :(得分:0)

所以我发现问题代码有2个问题

  • 第5行:(while i < c)应该是while @i < @c
  • 第10行:(set @i=i+1)应该是set @i=@i+1

感谢所有评论,帮助我弄清楚了