CREATE OR REPLACE PROCEDURE SCOTT.SP_TEST
(
P_PJT_CD IN VARCHAR2,
PC_CURSOR OUT SYS_REFCURSOR
) IS
V_RESULT_CD VARCHAR2(30 CHAR) := '';
V_RESULT_MSG VARCHAR2(500 CHAR) := '';
v_CNT NUMBER(22):=0;
v_id varchar(15 char) :='';
E_USER_ERROR_NO_DATA_FOUND EXCEPTION;
V_CODE VARCHAR(30 CHAR) := '';
V_MSG VARCHAR(30 CHAR) := '';
BEGIN
dbms_output.put_line('Start!!!!!-->');
begin
select row_id
into v_id
from TEST
where row_id ='9999';
-- exception
-- when no_data_found then
-- dbms_output.put_line('no data found');
-- V_CODE
-- RAISE E_USER_ERROR_NO_DATA_FOUND;
end;
OPEN PC_CURSOR
FOR
SELECT
'0000' AS RESULT_CD,
'111' AS RESULT_MSG
FROM DUAL;
dbms_output.put_line('end-->'||V_RESULT_MSG);
--EXCEPTION
-- WHEN OTHERS THEN
-- OPEN PC_CURSOR
-- FOR
-- SELECT
-- '333' AS RESULT_CD,
-- '444' AS RESULT_MSG
-- FROM DUAL;
END;
-------------------------------------------------------------
DB툴에서 아래 내용을 실행
------------------------------------------------
-- 프로시져 실행
-------------------------------------------------
DECLARE
i_counter integer;
v_cursor SYS_REFCURSOR;
v_RESULT_CD varchar2(100);
v_RESULT_MSG varchar2(500);
BEGIN
SCOTT.SP_TEST( P_PJT_CD => '',
PC_CURSOR => v_cursor);
i_counter := 0;
LOOP
FETCH v_cursor
INTO v_RESULT_CD,v_RESULT_MSG;
EXIT WHEN v_cursor%NOTFOUND;
i_counter := i_counter + 1;
DBMS_OUTPUT.PUT_LINE('결과:'||v_RESULT_CD|| v_RESULT_MSG);
END LOOP;
DBMS_OUTPUT.PUT_LINE('COUNT: ' || i_counter);
CLOSE v_cursor;
END;
'DBMS > 오라클 PLSQL' 카테고리의 다른 글
2. 기본 (0) | 2015.02.13 |
---|---|
1. PL/SQL 개요 (0) | 2015.02.11 |
pl/sql, procedure, function (0) | 2013.01.27 |