ストアドプロシージャではなく、実行する場合
変数なし
BEGIN -- NULL = NOP ... NO OPERATION NULL; END; /
変数を使う場合
DECLARE vNum NUMBER(2); BEGIN vNum := 1 ; DBMS_OUTPUT.PUT_LINE('数値=' || vNum); END; /
ストアドプロシージャ
CREATE PROCEDURE DISP_NUMBER IS vNum NUMBER(2); BEGIN vNum := 1 ; DBMS_OUTPUT.PUT_LINE('数値=' || vNum); END; /
コンパイルと実行
コンパイル
SET SERVEROUT ON @hoge.sql SHOW ERRORS PROCEDURE hoge
実行
VAR IN_hoge VARCHAR2(8) VAR OUT_hoge VARCHAR2(1) exec :IN_hoge := 'test' EXEC hoge(:IN_hoge, :OUT_hoge) PRINT OUT_HOGE
デバッグ
DBMS_OUTPUT.PUT_LINE('a')
サンプル
例1
declare /* cursor definition */ cursor c_test is select col1, col2 from test_tbl; begin for c_test_val in c_test loop DBMS_OUTPUT.PUT_LINE(c_test_val.col1); end loop; exception when others then DBMS_OUTPUT.PUT_LINE('error'); end; /
例2
declare /* カーソル型の定義 */ cursor c_test is select col1, col2 from test_tbl; /* カーソル用の変数定義 */ c_test_val c_test%rowtype; begin open c_test; loop fetch c_test into c_test_val; exit when c_test%notfound; end loop; close c_test; end; /
[カテゴリ: プログラミング言語 > PlSql]
[カテゴリ: プログラミング言語 > 基本]
[通知用URL]
Tweet
最終更新時間:2009年12月15日 21時25分33秒