mysql 預存程序和函數

來源:互聯網
上載者:User

1.什麼是預存程序與函數

mysql教程預存程序和函數是事先經過,編輯並儲存在資料庫教程中的一段sql語的集合,調用預存程序和函數可以簡化應用開發人員的工作,減少資料在資料庫和應用中的傳輸,從而提高mysql資料庫的處理能力。

2.預存程序相關函數與預存程序的建立,修改預存程序和函數。

  建立預存程序與建立函數

  create procedure sp_name()

   create function sp_name()

調用預存程序的執行個體

 call sp_name();

在mysql預存程序中允許包含dll語句,也可以在預存程序中運行提交commit,rollback等,但是注意預存程序中不能有load data infile語句,下面我們來看一個建立預存程序的執行個體。

mysql>delimiter $;

mysql>create procedure sp_111cn.net(in url int,in sitename int,out infodesc int)

->reads sql data

->begin

->select * from su where url== sitename and domain='www.111cn.net'

->select foun_rows() into p_asd;

->end $$;

->delimiter;

註明:上面是一個簡單的預存程序的執行個體,用來查詢domain='www.111cn.net'的資料,並返回。

好了,本站原創教程轉載註明來源www.111cn.net

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.