Home  >  Q&A  >  body text

linux - mysql stored procedure error reporting when calling

Please help me find out why the error is reported. This is my first time writing this type of stored procedure:
delimiter $$
create procedure mydb()
begin
declare dbname varchar(50);
declare stop int default 0;
declare cur cursor for (select name from name); //The name table stores the name of the database
declare CONTINUE HANDLER FOR SQLSTATE '02000' SET stop = null;
open cur;
fetch cur into dbname; //Traverse the name of the database
while (stop is not null) do

begin
declare name varchar(200);
declare stop1 int default 0;
declare cur1  cursor for (select prounit_name from dbname.prounit);  //获取prounit表中prounit_name字段内容
declare CONTINUE HANDLER FOR SQLSTATE '02000' SET stop1 = null;
open cur1;
fetch cur1 into name;
while ( stop1 is not null) do
    update prounit set name='abc';
    fetch cur1 into name;
end while;
close cur1;
end ;

fetch cur into dbname;
end while;
close cur;
end ;
delimiter $$

Error when executing stored procedure: ERROR 1146 (42S02): Table 'dbname.prounit' doesn't exist

why??????

滿天的星座滿天的星座2697 days ago804

reply all(2)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-31 10:39:32

    The prompt is obvious, the table does not exist
    declare dbname varchar(50);The name is overwritten?

    reply
    0
  • 迷茫

    迷茫2017-05-31 10:39:32

    Let’s talk about some grammar issues.

    1. while (stop is not null) stop in do should be the cursor dbname, and judge the cursor. Otherwise, stop will not be referenced

    2. The last end;, before you defined delimiter $$` with `$$ as the end character, it should be changed to end$$, and finally don’t forget to change the ending to delimiter;

    reply
    0
  • Cancelreply