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;#删除存储过程

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM