Home » SQL & PL/SQL » SQL & PL/SQL » Global variable in Stored Procedure
Global variable in Stored Procedure [message #36154] Wed, 07 November 2001 23:03 Go to next message
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 Go to previous messageGo to next message
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;
/

----------------------------------------------------------------------
Re: Global variable in Stored Procedure [message #36184 is a reply to message #36164] Thu, 08 November 2001 19:45 Go to previous message
syam
Messages: 5
Registered: August 2001
Junior Member
Thanks a lot Todd.

-Syam.

----------------------------------------------------------------------
Previous Topic: Re: OCP questions / Study circle/ experiences
Next Topic: how do i create an updatable cursor
Goto Forum:
  


Current Time: Mon May 20 03:25:41 CDT 2024