본문 바로가기

Database/PLSQL

038 - [Oracle PL/SQL] Procedure - Boolean/records as parameters

<샘플코드에서 사용한 데이터는 HR 스키마이고, 오라클 설치시 생성할 수 있는 기본 스키마 입니다>

 

 

 

# boolean을 이용한 조건문으로 로직처리

create or replace PROCEDURE p(x boolean) -- default is IN
is
begin

    if x then
    DBMS_OUTPUT.PUT_LINE('x is true');
    end if;
end;

-----
declare
    v boolean;
begin
    v:=true;
    p(v);
end;
----------------
x is true

 

 

 

# records를 이용하여 인자전달

create or replace PROCEDURE test_plsql_records
    ( rec in DEPARTMENTS%rowtype )
is
begin
    insert into DEPARTMENTS values rec;

end;

-------
declare
    v DEPARTMENTS%rowtype;
begin
    v.DEPARTMENT_ID:=3;
    v.DEPARTMENT_NAME:='v dept';

    test_plsql_records (v);
end;



select * from DEPARTMENTS
--------------------------------------------------------
DEPARTMENT_ID DEPARTMENT_NAME                MANAGER_ID LOCATION_ID
------------- ------------------------------ ---------- -----------
            3 v dept                                               
           10 Administration                        200        1700
           20 Marketing                             201        1800
           30 Purchasing                            114        1700
           40 Human Resources                       203        2400
...