Global variable in Stored Procedure [message #36154] |
Wed, 07 November 2001 23:03 |
syam
Messages: 5 Registered: August 2001
|
Junior Member |
|
|
Can any one suggest me how to declare a global variable in Stored Procedure in package level and access it in procedure body.
Thanks.
----------------------------------------------------------------------
|
|
|
Re: Global variable in Stored Procedure [message #36164 is a reply to message #36154] |
Thu, 08 November 2001 07:06 |
Todd Barry
Messages: 4819 Registered: August 2001
|
Senior Member |
|
|
You can declare a variable in the package spec (in which case it will be visible to any proc/function in the package, as well as others packages and standalone procs/functions), or in the package body (in which case it will be visible only to procs/functions in the package body).
create or replace package pkg_test
is
g_global_variable pls_integer; -- visible inside and outside this package
end;
/
create or replace package body pkg_test
is
g_private_variable pls_integer; -- visible only within this package body
procedure test
is
begin
-- I can see both here
dbms_output.put_line(g_global_variable);
dbms_output.put_line(g_private_variable);
end;
end;
/
end;
/
create or replace procedure standalone
is
begin
-- I can only see the global from here, but not the private
dbms_output.put_line(pkg_test.g_global_variable);
end;
/
----------------------------------------------------------------------
|
|
|
|