开发者社区> 问答> 正文

mysql 存储过程问题调用时候报错?报错

请帮忙看一下为什么会报错,小弟首次编写这种类型的存储过程:
delimiter $$
create procedure mydb()
begin
declare dbname varchar(50);
declare stop int default 0;
declare cur cursor for (select name from name); //name表中存放的是数据库的名称 
declare CONTINUE HANDLER FOR SQLSTATE '02000' SET stop = null;
open cur;
fetch cur into dbname; //遍历数据库的名称
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:ERROR 1146 (42S02): Table 'dbname.prounit' doesn't exist

why?????

展开
收起
爱吃鱼的程序员 2020-06-08 14:12:16 615 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    declaredbnamevarchar(50);

    sql直接运行只能填写实际表名

    dbname是一个字符串,不是数据库对象

    2020-06-08 14:12:32
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
搭建电商项目架构连接MySQL 立即下载
搭建4层电商项目架构,实战连接MySQL 立即下载
PolarDB MySQL引擎重磅功能及产品能力盛大发布 立即下载

相关镜像