-
Notifications
You must be signed in to change notification settings - Fork 0
/
5. Visibility of Package Objects (Code Samples).html
65 lines (58 loc) · 1.95 KB
/
5. Visibility of Package Objects (Code Samples).html
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<pre class="prettyprint linenums">---------------------------------------------------------------------------------------------
--------------------------------VISIBILITY OF VARIABLES IN PACKAGES--------------------------
---------------------------------------------------------------------------------------------
create or replace PACKAGE BODY EMP_PKG AS
v_sal_inc int := 500;
v_sal_inc2 int := 500;
procedure print_test is
begin
dbms_output.put_line('Test : '|| v_sal_inc);
end;
procedure increase_salaries AS
BEGIN
for r1 in cur_emps loop
update employees_copy set salary = salary + salary * v_salary_increase_rate
where employee_id = r1.employee_id;
end loop;
END increase_salaries;
function get_avg_sal(p_dept_id int) return number AS
v_avg_sal number := 0;
BEGIN
print_test;
select avg(salary) into v_avg_sal from employees_copy where
department_id = p_dept_id;
RETURN v_avg_sal;
END get_avg_sal;
END EMP_PKG;
-----------------
create or replace PACKAGE BODY EMP_PKG AS
v_sal_inc int := 500;
v_sal_inc2 int := 500;
function get_sal(e_id employees.employee_id%type) return number;
procedure print_test is
begin
dbms_output.put_line('Test : '|| v_sal_inc);
dbms_output.put_line('Test salary : '|| get_sal(102));
end;
procedure increase_salaries AS
BEGIN
for r1 in cur_emps loop
update employees_copy set salary = salary + salary * v_salary_increase_rate
where employee_id = r1.employee_id;
end loop;
END increase_salaries;
function get_avg_sal(p_dept_id int) return number AS
v_avg_sal number := 0;
BEGIN
print_test;
select avg(salary) into v_avg_sal from employees_copy where
department_id = p_dept_id;
RETURN v_avg_sal;
END get_avg_sal;
function get_sal(e_id employees.employee_id%type) return number is
v_sal number := 0;
begin
select salary into v_sal from employees where employee_id = e_id;
end;
end;
</pre>