-- 1.プロシージャ定義(パッケージ)
CREATE OR REPLACE PACKAGE PACK_PROC_SAMPLE
IS
PROCEDURE PROC_SAMPLE(
p_syori_kbn_i IN CHAR,
p_irai_no_i IN OUT CHAR,
p_irai_naiyou_o OUT VARCHAR2,
p_result_o OUT NUMBER
);
END;
/
-- 2.プロシージャ定義(パッケージ本体)
CREATE OR REPLACE PACKAGE BODY PACK_PROC_SAMPLE
IS
-- 定数宣言
c_proc_name CONSTANT VARCHAR(30) := 'PROC_SAMPLE';
-- 例外宣言
SYSTEM_ERROR EXCEPTION;
VALID_ERROR EXCEPTION;
PROCEDURE PROC_SAMPLE(
p_syori_kbn_i IN CHAR,
p_irai_no_i IN OUT CHAR,
p_irai_naiyou_o OUT VARCHAR2,
p_result_o OUT NUMBER
)
IS
-- 定数宣言
CHECK_OK CONSTANT PLS_INTEGER :=0;
PRM_ERR CONSTANT PLS_INTEGER :=1;
SYS_ERR CONSTANT PLS_INTEGER :=2;
BEGIN
-- 開始ログ出力
DBMS_OUTPUT.PUT_LINE( TO_CHAR(SYSTIMESTAMP,'yyyy/mm/dd hh24:mi:ss.ff3' || ' 処理開始');
-- 初期化
p_result_o := CHECK_OK;
-- 入力パラメタチェック
IF p_syori_kbn_i IS NULL
p_result_o := PRM_ERR;
RAISE VALID_ERROR;
END IF;
-- SQL CALL
SELECT A.IRAI_NAIYOU INTO p_irai_naiyou_o
FROM (
SELECT
IRAI_TBL.ID,
IRAI_TBL.IRAI_NAOYO
FROM IRAI_TBL
WHERE IRAI_TBL.IRAI_NO = p_irai_no_i
ORDER BY IRAI_TBL.ID DESC
) A
WHERE ROWNUM = 1;
-- 終了ログ出力
DBMS_OUTPUT.PUT_LINE( TO_CHAR(SYSTIMESTAMP,'yyyy/mm/dd hh24:mi:ss.ff3' || ' 処理終了');
-- 例外処理
EXCEPTION
WHEN VALID_ERROR THEN
DBMS_OUTPUT.PUT_LINE( TO_CHAR(SYSTIMESTAMP,'yyyy/mm/dd hh24:mi:ss.ff3' || ' VALID_ERROR');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE( TO_CHAR(SYSTIMESTAMP,'yyyy/mm/dd hh24:mi:ss.ff3' || ' OTHERS EXCEPTION');
p_result_o := SYS_ERR;
END PROC_SAMPLE;
END PACK_PROC_SAMPLE;
/
-- 3.プロシージャ呼出
-- 初期設定
SET TERMOUT OFF
SET TIMING OFF
SET SERVEROUTPUT OFF
SET ECHO OFF
SET LINE 2000
-- 変数定義
VARIABLE p_syori_kbn_i CHAR(1)
VARIABLE p_irai_no_i CHAR(10)
VARIABLE p_irai_naiyou_o VARCHAR2(30)
VARIABLE p_result_o NUMBER
-- 変数設定
BEGIN
:p_syori_kbn_i := '1';
:p_irai_no_i := '1234567890';
END;
/
-- ログ出力
SPOOL CALL_PROC_SAMPLE.log REPLACE
SET HEADING OFF
SELECT '#INPUT#' FROM DUAL;
SELECT 'p_syori_kbn_i : ' || :p_syori_kbn_i FROM DUAL;
SELECT 'p_irai_no_i : ' || :p_irai_no_i FROM DUAL;
SELECT TO_CHAR(SYSTIMESTAMP,'yyyy/mm/dd hh24:mi:ss.ff3' || ' ### PROC START ###' FROM DUAL;
SET HEADING ON
SET SERVEROUTPUT ON
CALL PROC_SAMPLE(:p_syori_kbn_i,:p_irai_no_i,:p_irai_naiyou_o,:p_result_o);
SET SERVEROUTPUT OFF
SET HEADING OFF
SELECT TO_CHAR(SYSTIMESTAMP,'yyyy/mm/dd hh24:mi:ss.ff3' || ' ### PROC END ###' FROM DUAL;
SELECT '#OUTPUT#' FROM DUAL;
SELECT 'p_syori_kbn_i : ' || :p_syori_kbn_i FROM DUAL;
SELECT 'p_irai_no_i : ' || :p_irai_no_i FROM DUAL;
SELECT 'p_irai_naiyou_o : ' || :p_irai_naiyou_o FROM DUAL;
SELECT 'p_result_o : ' || :p_result_o FROM DUAL;
SET HEADING ON
-- ログ出力終了
SPOOL OFF
【このカテゴリーの最新記事】
- no image
- no image