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??????
The prompt is obvious, the table does not exist
declare dbname varchar(50);
The name is overwritten?Let’s talk about some grammar issues.
while (stop is not null)
stopin do
should be the cursordbname
, and judge the cursor. Otherwise, stop will not be referencedThe last
end;
, before you defineddelimiter $$` with `$$
as the end character, it should be changed toend$$
, and finally don’t forget to change the ending todelimiter;