DB/ORACLE

[Oracle - PL_SQL] SYS_REFCURSOR 커서 출력

Kang_hobin 2022. 5. 2. 14:44
CREATE OR REPLACE PROCEDURE TEST
(
	pSystemSe IN varchar2, 
	pTableName IN varchar2, 
	oCursor OUT SYS_REFCURSOR
	--oErrCode OUT Number
)
IS 
BEGIN 
	OPEN oCursor FOR
		SELECT COLUMN_NAME, COLUMN_COMMENTS FROM TEST_TABLE
		WHERE SYSTEM_SE = pSystemSe AND TABLE_NAME = pTableName;
	EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('SQL ERROR MESSAGE: ' || SQLERRM);
END TEST;

 

DECLARE
    COLUMN_NAME        VARCHAR2(100);
    COLUMN_COMMENTS    VARCHAR2(100);
    v_test_refcur    SYS_REFCURSOR;
BEGIN
    DBMS_OUTPUT.PUT_LINE(RPAD('COLUMN_NAME', 50, ' ') || '| COLUMN_COMMENTS');
    DBMS_OUTPUT.PUT_LINE(RPAD('-', 100, '-'));
    TEST('AA','AAAA', v_test_refcur);
    LOOP
        FETCH v_test_refcur INTO COLUMN_NAME, COLUMN_COMMENTS;
        EXIT WHEN v_test_refcur%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE(RPAD(COLUMN_NAME, 50, ' ') || '| ' || COLUMN_COMMENTS);
    END LOOP;
    CLOSE v_test_refcur;
END;

SYS_REFCURSOR 루프돌리기

'DB > ORACLE' 카테고리의 다른 글

DB 테이블 권한 부여  (0) 2022.07.05
오라클 FK, PK 포함 스키마 조회하기  (0) 2022.06.09
Oracle Data Insert 시 fk 오류(Disable constraints)  (0) 2022.05.12
계층형 쿼리  (0) 2022.01.17
누적 집계 함수 (SUM OVER)  (0) 2021.09.06