ORACLE SQL

[ORACLE] SQL - TYPE의 is record 활용하기

그릿GRIT 2021. 3. 21. 00:36
728x90

1.  is record 안에 변수명, 타입을 넣어준다.

2. 만든 타입으로 변수(aa)를 만든다.

3. select ~~ into를 이용하여 column의 값들을 aa에 넣는다.

4. aa.해당 변수를 써서 해당 값을 읽어올수있다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
declare
    type aa_type is record(
        v_fname employees.first_name%TYPE, 
        v_lname employees.last_name%TYPE,
        v_sal employees.salary%TYPE,
        v_deptno employees.department_id%TYPE
        );
    aa aa_type;
begin
    SELECT first_name,last_name,salary,department_id
    into aa
    from employees
    where employee_id = 200;
    
     DBMS_OUTPUT.PUT_LINE(aa.v_fname);
     DBMS_OUTPUT.PUT_LINE(aa.v_lname);
     DBMS_OUTPUT.PUT_LINE(aa.v_sal);
     DBMS_OUTPUT.PUT_LINE(aa.v_deptno);
end;
/
cs