s
o
u
l
s
j
i
e

MySQL创建存储过程

1.查询某个数据库的中存在的存储过程

use mvc_study;#选择数据库
show procedure status where Db='mvc_study';#查询数据库中存在的存储过程

 2.创建一个无参数的数据库存储过程并执行

create procedure hi() select 'hello';#创建一个简单的存储过程
call hi();#执行这个存储过程

 3.创建有参数的存储过程并执行

create procedure test02(a int,b int)#创建带参数的存储过程
begin 
      declare c int;
      if a is null then
         set a=0;
      end if ;
      if b is null then
         set b=0;
      end if ;
      set c =a +b;
      select c as sum;
end;
call test02(10,20);#执行带参数的存储过程

set @aa=150;
set @bb=120;
call test02(@aa,@bb);#执行带参数的存储过程

 

3.删除存储过程

drop procedure procedurename;#删除存储过程

 

posted @ 2018-01-03 15:10  soulsjie  阅读(3120)  评论(0编辑  收藏  举报
你累吗?累就对了,当你觉得累时证明你在走上坡路!-----NotFoundObject - 2016-12-14 08:43