본문 바로가기

ORACLE SQL

[ORACLE] SQL - TYPE변수 생성해서 사용하기

728x90

안녕하세요. TYPE변수 생성해서 사용하는 예시 공유합니다.

오라클 책에서 실습해보고 복습하기 위해 올려두었습니다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
create or replace procedure ABCDE AS
    Type mytype1 is varray(3) of number(10);
    Type mytype2 is table of nvarchar2(10);
    Type mytype3 is table of number(5) index by string(10);
    my1 mytype1;
    my2 mytype2;
    my3 mytype3;
    idx varchar2(10);
 
begin
    my1 := mytype1(5,10,15);
    my2 := mytype2('안녕','이것','저것');
    my3('첫번째') := 1000;
    my3('두번째') := 2000;
    my3('세번째') := 3000;
 
    FOR i IN 1..3 LOOP
        DBMS_OUTPUT.PUT_LINE(my1(i)||my2(i));
    END LOOP;
    
    idx := my3.FIRST;
    
    WHILE idx is not null LOOP
            DBMS_OUTPUT.PUT_LINE(idx || '==>'||my3(idx));
            idx := my3.next(idx);
    END LOOP;
 
end;
/
 
execute ABCDE;
cs