You are on page 1of 7

TO PROCEDURE KHNG C THAM S :

CREATE OR REPLACE PROCEDURE ten_proc

AS

BEGIN

END ten_proc;

TO PROCEDURE C THAM S :

CREATE OR REPLACE PROCEDURE ten_proc

( tham_so_1 IN kieu_cua_tham_so,

tham_so_2 IN kieu_cua_tham_so

AS

BEGIN

END ten_proc;

TO PROCEDURE C BIN :

CREATE OR REPLACE PROCEDURE ten_proc

bien_1 kieu_cua_bien_1(chieu_dai_kieu_bien);

bien_2 kieu_cua_bien_2(chieu_dai_kieu_bien);

AS

BEGIN

END ten_proc;

Hoc

CREATE OR REPLACE PROCEDURE ten_proc

bien_1 ten_table.ten_field_1%TYPE;
bien_2 ten_table.ten_field_2%TYPE;

AS

BEGIN

END ten_proc;

TO PROCEDURE XUT KT QU RA DBMS OUTPUT (View DBMS Output) :

CREATE OR REPLACE PROCEDURE ten_proc

IS

BEGIN

DBMS_OUTPUT.PUT_LINE();

END ten_proc;

V d to Procedure add 1 record vo table PERSONS c 2 bin x, y cng kiu vi


2 field ca PERSONS :

CREATE OR REPLACE procedure MY_TEST4


(x PERSONS.P_ID%TYPE,
y PERSONS.LASTNAME%TYPE)
as
begin
insert into PERSONS(P_ID, LASTNAME) values (x,y);
end MY_TEST4;
/

Exec MY_TEST4(1,Thuy Hong)

V d to Procedure c khai bo bin v1, v2, v3, v4 :


CREATE OR REPLACE procedure THANHTK.sp_TB_PTD_Crosstab_Org
(w_period in varchar2, w_seg_fr in varchar2, w_seg_to in varchar2)
as
v1 varchar2(3);
v2 number;
v3 varchar2(4);
v4 number;
begin
-- Buoc 1 :
delete tmpTB_Org;
v3:='20' || substr(w_period,5,2);
v4:=to_number(v3);
v1:=substr(w_period,1,3);
if v1='JAN' then
v2:=1;
end if;
if v1='FEB' then
v2:=2;
end if;
if v1='MAR' then
v2:=3;
end if;
if v1='APR' then
v2:=4;
end if;
if v1='MAY' then
v2:=5;
end if;
if v1='JUN' then
v2:=6;
end if;
if v1='JUL' then
v2:=7;
end if;
if v1='AUG' then
v2:=8;
end if;
if v1='SEP' then
v2:=9;
end if;
if v1='OCT' then
v2:=10;
end if;
if v1='NOV' then
v2:=11;
end if;
if v1='DEC' then
v2:=12;
end if;

-- Buoc 2 :
insert into tmpTB_Org
select C.segment1, C.segment4, E.description, D.currency_code, D.Actual_Flag,
NVL((select sum(NVL(D1.Begin_Balance_Dr,0)) - sum(NVL(D1.Begin_Balance_Cr,0))
from gl.gl_balances D1, gl.gl_code_combinations C1, apps.fnd_flex_values_vl E1
where D1.Code_Combination_Id = C1.CODE_COMBINATION_ID
and C1.Segment4 = E1.FLEX_VALUE
and D1.period_num = v2 -- HERE is BEG_BAL
and D1.period_year = v4 -- HERE
and C1.segment1 = C.segment1 -- HERE
and C1.segment4 = C.segment4
and D1.currency_code = D.currency_code
and D1.Actual_Flag = D.Actual_Flag
group by C1.Segment4
),0) BEG_BAL,
sum(NVL(D.Period_Net_Dr,0)) DEBIT,
sum(NVL(D.Period_Net_Cr,0)) CREDIT,
(NVL((select sum(NVL(D1.Begin_Balance_Dr,0)) - sum(NVL(D1.Begin_Balance_Cr,0))
from gl.gl_balances D1, gl.gl_code_combinations C1, apps.fnd_flex_values_vl E1
where D1.Code_Combination_Id = C1.CODE_COMBINATION_ID
and C1.Segment4 = E1.FLEX_VALUE
and D1.period_num = v2 -- HERE is BEG_BAL = 1
and D1.period_year = v4 -- HERE
and C1.segment1 = C.segment1 -- HERE
and C1.segment4 = C.segment4
and D1.currency_code = D.currency_code
and D1.Actual_Flag = D.Actual_Flag
group by C1.Segment4
),0)
+
sum(NVL(D.Period_Net_Dr,0))
-
sum(NVL(D.Period_Net_Cr,0))
) END_BAL
from gl.gl_balances D, gl.gl_code_combinations C, apps.fnd_flex_values_vl E
where D.Code_Combination_Id = C.CODE_COMBINATION_ID
and C.segment4 = E.FLEX_VALUE
-- Chu y : neu chay ADJ thi o day phai go tu 1->13 neu la YTD
and D.period_num in (v2) -- HERE to get Debits Credits YTD
and D.period_year = v4 -- HERE
-- and C.segment1 = '04' -- HERE
and C.Segment4 between w_seg_fr and w_seg_to -- HERE
and D.currency_code = 'VND'
and E.summary_flag <> 'Y'
and D.Actual_Flag = 'A'
group by C.segment1, C.segment4, E.description, D.currency_code, D.Actual_Flag
having
(select sum(NVL(D1.Begin_Balance_Dr,0)) - sum(NVL(D1.Begin_Balance_Cr,0))
from gl.gl_balances D1, gl.gl_code_combinations C1, apps.fnd_flex_values_vl E1
where D1.Code_Combination_Id = C1.CODE_COMBINATION_ID
and C1.Segment4 = E1.FLEX_VALUE
and D1.period_num = v2 -- HERE is BEG_BAL = 1
and D1.period_year = v4 -- HERE
and C1.segment1 = C.segment1 -- HERE
and C1.segment4 = C.segment4
and D1.currency_code = D.currency_code
and D1.Actual_Flag = D.Actual_Flag
group by C1.Segment4
) <> 0
or sum(NVL(D.Period_Net_Dr,0)) <> 0
or sum(NVL(D.Period_Net_Cr,0)) <> 0
order by C.segment4;
end sp_TB_PTD_Crosstab_Org;
/

V d to Procedure update 1 field trong table :

CREATE OR REPLACE PROCEDURE THANHTK.raise_salary


(my_empno in number, amount in number)
IS
BEGIN
UPDATE tmpEMP SET sal = sal + amount WHERE empno = my_empno;
END raise_salary;
/

Exec raise_salary(1,400)
Vi du 1

create or replace procedure my_sp


as
max_bill_date date;
begin

select max(bill_dt) into max_bill_date from bill_cycle;

delete trichloc3;

insert into trichloc3


select * from bill
where bill_dt=max_bill_date
and tot_charg_amt>0
and substr(cell_agency_id,2,1) = '1';

commit;

end my_sp;
/

Vi du 2 :

create or replace procedure my_sp(my_agency IN varchar2)


as
max_bill_date date;
begin

select max(bill_dt) into max_bill_date from bill_cycle;

delete trichloc3;

insert into trichloc3


select * from bill
where bill_dt=max_bill_date
and tot_charg_amt>0
and substr(cell_agency_id,2,1) = get_agency_id(my_agency);

commit;

end my_sp;
/
Function

create or replace function get_agency_id(vAgency in varchar2)


return varchar2 is vZone varchar2(1);
begin
vZone := substr(vAgency,2,1);
return vZone;
end;
/

exec my_sp('C20003')

You might also like