创建存储过程
create or replace package pkg_pv is
procedure set_pv(pv varchar2);
function get_pv return varchar2;
end;
create or replace package body pkg_pv is
v varchar2(20);
procedure set_pv(pv varchar2) is begin v:=pv; end;
function get_pv return varchar2 is begin return v; end;
end;
创建带参视图
create view v_emp as select * from emp where ename=pkg_pv.get_pv();
调用过程,结果正确执行
begin
pkg_pv.setpv('scotte');
end;
select * from v_emp;
按照此方法我们可以把通过包的形式来创建一个系统变量,通过在运行时设置其值。来获得对一些需要在运行时有不同值需求的业务处理作一些更简化的处理。本例中我们甚至可以在包体里面它设一个初始值,如果不单独设置时,就采用初值。这样就可以获得更大的灵活性