oracle存儲過程學習筆記1–基本結構

存儲過程(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 ];

無參存儲過程示例:

createorreplaceprocedurehelloWorldIS BEGIN   dbms_output.put_line('hell world!'); END helloWorld;

有參存儲過程示例:

createorreplaceproceduretest_param(test_idINnumber)IS BEGIN   dbms_output.put_line(test_id); END test_param;

無參存儲過程的運行:
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窗口下部的表格的第三列中輸入測試參數,輸入測試參數之後,再點擊運行;
其他步驟相同。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章