首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mysql存储过程+更新查询

问Mysql存储过程+更新查询
EN

Stack Overflow用户
提问于 2013-09-07 15:07:44
回答 1查看 2.9K关注 0票数 1

问题出在mysql过程中。我想在mysql过程中运行一个更新查询。我已经创建了该过程并调用它,没有任何错误。但问题是过程中的update查询没有被执行。

代码语言:javascript
复制
delimiter $$
create procedure update_member_status(IN new_mem_id int,IN mem_count int)
begin

declare tot_ref_count,mem_ref_id int default 0;

select ref_id into mem_ref_id
from ccf_user
where user_id=new_mem_id;

select ref_count into tot_ref_count 
from ccf_user
where user_id=mem_ref_id;

if tot_ref_count = mem_count then
update ccf_user 
set status='permanent'
where user_id=mem_ref_id;
else
update ccf_user 
set status='*****'
where user_id=mem_ref_id;
end if;

end
$$

然后我调用了这个过程:-调用update_member_status(25,6)

我希望执行过程中的更新查询

EN

回答 1

Stack Overflow用户

发布于 2013-09-07 18:26:34

我将从将此过程重写为一条SQL语句开始:

代码语言:javascript
复制
UPDATE ccf_user c1, ccf_user c2
   SET c1.status = 
       CASE WHEN c1.ref_count = @mem_count 
            THEN 'permament' ELSE '*****' END
WHERE c1.user_id = c2.ref_id
      AND c2.user_id = @new_mem_id
;

然后分析它是否提供了预期的结果,例如使用以下命令:http://www.sqlfiddle.com/#!2/2310b/1

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18670752

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档