linux - mysql stored procedure error reporting when calling
滿天的星座
滿天的星座 2017-05-31 10:37:32
0
2
697

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??????

滿天的星座
滿天的星座

reply all (2)
淡淡烟草味

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

    迷茫

    Let’s talk about some grammar issues.

    1. while (stop is not null)stopin doshould be the cursordbname, and judge the cursor. Otherwise, stop will not be referenced

    2. The lastend;, before you defineddelimiter $$` with `$$as the end character, it should be changed toend$$, and finally don’t forget to change the ending todelimiter;

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!