linux 调用mysql存储过程_linux - 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?????

解决方案

说几个语法问题吧.

while ( stop is not null) do中的stop应该游标dbname才对,对游标进行判断.不然对stop没有引用过

最后一个end;,前面你定义了delimiter $$`以`$$为结束符,应该改为end$$,最后不要忘了结尾改成delimiter ;

992918a26da18f46479e2b9a26bece7f.png

扫一扫关注IT屋

微信公众号搜索 “ IT屋 ” ,选择关注与百万开发者在一起

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值