mysql 預存程序文法建立與查看(1/5)

來源:互聯網
上載者:User

文章提供一款mysql教程 預存程序文法建立與查看哦,關於一個預存程序包括名字,參數列表,以及可以包括很多sql語句的sql語句集,下面來看看建立預存程序和查看預存程序吧。

建立預存程序:

查詢資料庫教程中的預存程序

 

方法一:

       select `name` from mysql.proc where db = 'your_db_name' and `type` = 'procedure'

 

方法二:

         show procedure status;

 

 

查看預存程序或函數的建立代碼

 

show create procedure proc_name;
show create function func_name;

 


文法:

create procedure p()

begin

/*此預存程序的本文*/

end 
create procedure productpricing()

begin

    select avg(pro_price) as priceaverage

    from products;

end;

# begin…end之間是預存程序的主體定義

# mysql的分界符是分號(;) 

                        

調用預存程序的方法是:

 

# call加上過程名以及一個括弧

# 例如調用上面定義的預存程序

call productpricing();

# 哪怕是不用傳遞參數,預存程序名字後面的括弧“()”也是必須的 

刪除預存程序的方法是:

 

drop procudure productpricing; 

建立帶參數的預存程序:

 

create procudure productpricing(

out p1 decimal(8,2),

out ph decimal(8,2),

out pa decimal(8,2)

)

begin

select min(prod_price) into pl from products;

select max(prod_price) into ph from products;       

select avg(prod_price) into pa from products;

end;

# decimal用於指定參數的資料類型

# out用於表明此值是用於從預存程序裡輸出的

# mysql支援 out, in, inout 

首頁 1 2 3 4 5 末頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.