pl/sql package
1 --package 1: create a package
2 create or replace package MyPack
3 as
4 function getHisalAccordingGrade(inGrade in salgrade.hisal%type)
5 return salgrade.hisal%type;
6 procedure getAvgHisal
7 (v_average out number);
8 end;
9
10
11 create or replace package body MyPack
12 AS
13 procedure getAvgHisal
14 (v_average out number)
15 as
16 begin
17 select AVG(hisal) into v_average
18 from salgrade;
19 end getAvgHisal;
20
21 function getHisalAccordingGrade(inGrade in salgrade.hisal%type)
22 return salgrade.hisal%type
23 as
24 outHisal salgrade.hisal%type;
25 begin
26 select hisal into outHisal
27 from salgrade where grade = inGrade;
28 return outHisal;
29 end getHisalAccordingGrade;
30 end MyPack;
31
32
33 --call MyPack
34 set serveroutput on;
35 declare
36 v_hisal salgrade.hisal%type := 0;
37 v_average salgrade.hisal%type := 0;
38 begin
39 v_hisal := MyPack.getHisalAccordingGrade(1);
40 dbms_output.put_line(v_hisal);
41
42 MyPack.getAvgHisal(v_average);
43 dbms_output.put_line(v_average);
44 end;
45
2 create or replace package MyPack
3 as
4 function getHisalAccordingGrade(inGrade in salgrade.hisal%type)
5 return salgrade.hisal%type;
6 procedure getAvgHisal
7 (v_average out number);
8 end;
9
10
11 create or replace package body MyPack
12 AS
13 procedure getAvgHisal
14 (v_average out number)
15 as
16 begin
17 select AVG(hisal) into v_average
18 from salgrade;
19 end getAvgHisal;
20
21 function getHisalAccordingGrade(inGrade in salgrade.hisal%type)
22 return salgrade.hisal%type
23 as
24 outHisal salgrade.hisal%type;
25 begin
26 select hisal into outHisal
27 from salgrade where grade = inGrade;
28 return outHisal;
29 end getHisalAccordingGrade;
30 end MyPack;
31
32
33 --call MyPack
34 set serveroutput on;
35 declare
36 v_hisal salgrade.hisal%type := 0;
37 v_average salgrade.hisal%type := 0;
38 begin
39 v_hisal := MyPack.getHisalAccordingGrade(1);
40 dbms_output.put_line(v_hisal);
41
42 MyPack.getAvgHisal(v_average);
43 dbms_output.put_line(v_average);
44 end;
45