create table employees as select * from hr.employees
Table created.
create or replace package pkg authid definer
is
g_force_upper boolean := false;
end;
Package created.
Without result cache
create or replace function last_name (
p_employee_id in integer
) return varchar2 is
l_name varchar2(1000);
begin
select last_name
into l_name
from employees
where employee_id = p_employee_id;
return
case
when pkg.g_force_upper then
upper(l_name)
else l_name
end;
end;
Function created.
begin
dbms_output.put_line (last_name (100));
end;
Statement processed.
King
begin
pkg.g_force_upper := true;
dbms_output.put_line (last_name (100));
end;
Statement processed.
KING
begin
pkg.g_force_upper := false;
end;
Statement processed.
With result cache
create or replace function last_name (
p_employee_id in integer,
p_force_upper_case in boolean default false
) return varchar2
result_cache
is
l_name varchar2(100);
begin
select last_name
into l_name
from employees
where employee_id = p_employee_id;
return
case
when p_force_upper_case then
upper(l_name)
else l_name
end;
end;
Function created.
begin
dbms_output.put_line (last_name (100));
end;
Statement processed.
King
Dirty Data!
begin
pkg.g_force_upper := true;
dbms_output.put_line(last_name(100));
end;
Statement processed.
King