存儲過程(Procedure)的定義:
A named PL/SQL block that performs one or more actions and is called as an executable PL/SQL statement. You can pass information into and out of a procedure through its parameter list.
存儲過程的結構如下:
PROCEDURE name [ ( parameter [, parameter ... ] ) ]
IS
[declaration statements]
BEGIN
executable-statements
[ EXCEPTION
exception handler statements]
END [ name ];
無參存儲過程示例:
有參存儲過程示例:
無參存儲過程的運行:
1、首先打開PL/SQL Developer,連接到一個測試數據庫;
2、選擇file –>new –> program window –> blank,新建一個編程窗口;
3、把代碼黏貼進去或者敲進去;
4、點擊工具欄上的齒輪按鈕或者用快捷鍵F8,編譯該存儲過程;
5、在左側的對象瀏覽器窗口中展開 Procudures,找到剛纔編譯的存儲過程,沒有的話刷新一下再找找看;
6、選中存儲過程,點擊右鍵,選擇test;
7、點擊工具欄上的齒輪按鈕或者用快捷鍵F8,運行該存儲過程;
8、在DBMS Outputs 標籤頁中可以看到輸出:hell world!。
有參存儲過程的運行:
在步驟7運行存儲過程的時候,可以在Test script窗口下部的表格的第三列中輸入測試參數,輸入測試參數之後,再點擊運行;
其他步驟相同。