728x90
1개의 매개변수를 받고 1개를 출력하도록 하는 프로시저 예시입니다.
|
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
|
--번호 입력을 위한 sequence를 생성하였습니다.
create sequence hh_sequence;
--프로시저를 실행하였을 때의 값을 저장하기 위한 테이블을 생성하였습니다.
create table hh_table (id_num number(38), first_name varchar2(20));
--프로시저를 만들때, 매개변수로 v_fname을 받고 v_lname을 출력하도록 하였습니다.
create or replace procedure hh_pro (
v_fname in employees.first_name%type,
v_lname out employees.last_name%type
) as
--begin 에서는 insert를 통해서 hh_table에 sequence숫자와, v_fname이 입력되도록 하였습니다.
--select를 통해서 v_fname에 해당되는 last_name을 가져와서 v_lame에 담도록 하였습니다.
begin
insert into hh_table values(hh_sequence.nextval, v_fname);
select last_name into v_lname from employees where first_name = v_fname;
end;
/
--프로시저 hh_pro('Sundar',outdata)를 begin부에 넣어 'Sundar'라는 이름을 sequence번호와 함께 hh_table에
--입력되도록 하였으며, 또한 'Sundar'에 해당하는 last_name이 outdata에 저장되도록 하였습니다.
declare
outdata varchar2(25);
begin
hh_pro('Sundar',outdata);
DBMS_OUTPUT.PUT_LINE(outdata);
end;
/
|
cs |