mysql 5.0預存程序學習

來源:互聯網
上載者:User

一.建立預存程序

  1.基本文法:

  create procedure sp_name()

  begin

  .........

  end

  2.參數傳遞

  二.調用預存程序

  1.基本文法:call sp_name()

  注意:預存程序名稱後面必須加括弧,哪怕該預存程序沒有參數傳遞

  三.刪除預存程序

  1.基本文法:

  drop procedure sp_name//

  2.注意事項

  (1)不能在一個預存程序中刪除另一個預存程序,只能調用另一個預存程序

  四.區塊,條件,迴圈

  1.區塊定義,常用

  begin

  ......

  end;

  也可以給區塊起別名,如:

  lable:begin

  ...........

  end lable;

  可以用leave lable;跳出區塊,執行區塊以後的代碼

  2.條件陳述式

以下為引用的內容:
if 條件 then
statement
else
statement
end if;

  3.迴圈語句

  (1).while迴圈

以下為引用的內容:
[label:] WHILE expression DO
  statements
  END WHILE [label] ;

  (2).loop迴圈

以下為引用的內容:
  [label:] LOOP
  statements
  END LOOP [label];

  (3).repeat until迴圈

以下為引用的內容:
  [label:] REPEAT
  statements
  UNTIL expression
  END REPEAT [label] ;

  五.其他常用命令

  1.show procedure status

  顯示資料庫中所有儲存的預存程序基本資料,包括所屬資料庫,預存程序名稱,建立時間等

  2.show create procedure sp_name

  顯示某一個預存程序的詳細資料

聯繫我們

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