<샘플코드에서 사용한 데이터는 HR 스키마이고, 오라클 설치시 생성할 수 있는 기본 스키마 입니다>
/*
1- create a procedure that take emp_id as parameter and
return the firat_name and salary
note: use bind variable to print the firat_name and salary
*/
create or replace procedure query_emp
(
p_emp_id employees.employee_id%type,
p_f_name out employees.first_name%type,
p_sal out employees.salary%type
)
is
begin
select first_name,salary
into p_f_name,p_sal
from employees
where employee_id=p_emp_id;
exception
when others then
dbms_output.put_line(sqlcode);
dbms_output.put_line(sqlerrm);
end;
-----------------------------------------------------------------------
--you should declare 2 bind variables
variable b_first_name varchar2(100)
variable b_sal number
# 변수앞에 ':' 표시 빠지지않게 할것.
execute query_emp(105,:b_first_name,:b_sal );
print b_first_name b_sal ;
-----------------------------------------------------------------------
B_FIRST_NAME
----------------
David
B_SAL
----------
4800
--2 the other way to print the out parameter
declare
v_first_name employees.first_name%type;
v_sal employees.salary%type;
begin
query_emp(105,v_first_name,v_sal );
dbms_output.put_line(v_first_name);
dbms_output.put_line(v_sal);
end;
-----------------------------------------------------------------------
David
4800
'Database > PLSQL' 카테고리의 다른 글
035 - [Oracle PL/SQL] Procedure - 인자 전달하는 방법 3가지 (0) | 2024.02.23 |
---|---|
034 - [Oracle PL/SQL] Procedure - (IN OUT parameter) (0) | 2024.02.23 |
032 - [Oracle PL/SQL] Procedure - (IN parameter)/ Error 처리 (0) | 2024.02.23 |
031 - [Oracle PL/SQL] Procedure (0) | 2024.02.22 |
030 - [Oracle PL/SQL] Exceptions - Group Functions and Blocks (0) | 2024.02.21 |