Global Variable in PL/SQL

Non-Across Sessions

create or replace package test_pkg
as
  global_var number :=1;
  constant_var CONSTANT NUMBER := 2;
end;

Across Sessions

create table global_value ( x int );
insert into global_value values ( 0 );


create or replace package get_global
as
   function val return number;
   procedure set_val( p_x in number );
end;
/

create or replace package body get_global
as

function val return number
as
   l_x number;
begin
   select x into l_x from global;
   return l_x;
end;

procedure set_val( p_x in number )
as
  pragma autonomous_transaction;
begin
   update global set x = p_x;
   commit;
end;

end;
/


你可能感兴趣的:(variable)