Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the ultimate-member domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /ledcorps/www/wp/wp-includes/functions.php on line 6114 3.2.4 PL/SQL Table of Record – 대나무숲

3.2.4 PL/SQL Table of Record

출처 http://www.gurubee.net/lecture/1049

PL/SQL TABLE변수 선언과 비슷하며 데이터타입을 %ROWTYPE으로 선언하면 된다.

  PL/SQL TABLE과 RECORD의 복합 기능을 한다.

PL/SQL Table Of Record 문법

 
-- 선언 예제
TYPE dept_table_type IS TABLE OF dept%ROWTYPE
INDEX BY BINARY_INTEGER; 

-- Each element of dept_table  is a record 
dept_table   dept_table_type;

-- 아래 프로시저에서 사용된 예제를 보면 이해가 쉽게 갈 것이다.
    

PL/SQL Table Of Record 예제

 
CREATE OR REPLACE PROCEDURE Table_Test
  IS
  
    i BINARY_INTEGER := 0;
 
    -- PL/SQL Table of Record의 선언
    TYPE dept_table_type IS TABLE OF dept%ROWTYPE
    INDEX BY BINARY_INTEGER;
 
    dept_table dept_table_type;
 
  BEGIN
  
    FOR dept_list IN (SELECT * FROM dept) LOOP
 
      i:= i+1;
  
      -- TABLE OF RECORD에 데이터 보관
      dept_table(i).deptno := dept_list.deptno ;     
      dept_table(i).dname := dept_list.dname ;
      dept_table(i).loc   := dept_list.loc ;
 
    END LOOP;
 
    FOR cnt IN 1..i LOOP
 
       -- 데이터 출력
       DBMS_OUTPUT.PUT_LINE( '부서번호 : ' || dept_table(cnt).deptno || 
                             '부서명 : ' ||  dept_table(cnt).dname || 
                               '위치 : ' || dept_table(cnt).loc );
 
    END LOOP;
 
 END;
/
 
 
SQL> SET SERVEROUTPUT ON ;

SQL> EXECUTE Table_test;
부서번호 : 10부서명 : ACCOUNTING위치 : NEW_YORK
부서번호 : 20부서명 : RESEARCH위치 : DALLAS
부서번호 : 30부서명 : 인사과위치 : CHICAGO
부서번호 : 40부서명 : OPERATIONS위치 : BOS%TON
 
PL/SQL 처리가 정상적으로 완료되었습니다.
    

답글 남기기 0

Your email address will not be published. Required fields are marked *