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