1 -- function 1: get hisal according to the grade(1 parameter)
2 Create or replace function getHisalAccordingGrade(inGrade in salgrade.hisal%type)
3 return salgrade.hisal%type
4 as
5 outHisal salgrade.hisal%type;
6 begin
7 select hisal into outHisal
8 from salgrade where grade = inGrade;
9 return outHisal;
10 end;
11
12
13 set serveroutput on;
14 declare
15 varHisal salgrade.hisal%type;
16 begin
17 varHisal := getHisalAccordingGrade(1);
18 dbms_output.put_line(varHisal);
19 end;
20
21 -- function 2: get the average of the hisal(no in-parameter)
22 create or replace function getAverageHisal
23 return salgrade.hisal%type
24 as
25 outAvgHisal salgrade.hisal%type;
26 begin
27 select AVG(hisal) into outAvgHisal
28 from salgrade;
29 return outAvgHisal;
30 end;
31
32 set serveroutput on;
33 declare
34 varHisal salgrade.hisal%type;
35 begin
36 varHisal := getAverageHisal();
37 dbms_output.put_line(varHisal);
38 end;
39
40
2 Create or replace function getHisalAccordingGrade(inGrade in salgrade.hisal%type)
3 return salgrade.hisal%type
4 as
5 outHisal salgrade.hisal%type;
6 begin
7 select hisal into outHisal
8 from salgrade where grade = inGrade;
9 return outHisal;
10 end;
11
12
13 set serveroutput on;
14 declare
15 varHisal salgrade.hisal%type;
16 begin
17 varHisal := getHisalAccordingGrade(1);
18 dbms_output.put_line(varHisal);
19 end;
20
21 -- function 2: get the average of the hisal(no in-parameter)
22 create or replace function getAverageHisal
23 return salgrade.hisal%type
24 as
25 outAvgHisal salgrade.hisal%type;
26 begin
27 select AVG(hisal) into outAvgHisal
28 from salgrade;
29 return outAvgHisal;
30 end;
31
32 set serveroutput on;
33 declare
34 varHisal salgrade.hisal%type;
35 begin
36 varHisal := getAverageHisal();
37 dbms_output.put_line(varHisal);
38 end;
39
40