ITPub博客

首页 > 数据库 > Oracle > Global Variable in PL/SQL

Global Variable in PL/SQL

原创 Oracle 作者:pan_tian 时间:2014-07-02 16:08:10 0 删除 编辑

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;
/


<!-- Baidu Button BEGIN -->

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26687597/viewspace-1204842/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Windows7下把窗口设置成保护眼睛豆沙绿色
下一篇: SQL Query to get Oracle Menus & Functions
请登录后发表评论 登录
全部评论
暂无介绍

注册时间:2012-02-18

最新文章