Link to home
Start Free TrialLog in
Avatar of jeet1234
jeet1234

asked on

Oracle Package Variables

Hi,
I need some info about Oracle Package Variables..can
anyone recommend a good site.
Let me explain my problem a bit...
I am calling one procedure in an Oracle Package which is using Package Variables initilized to Null.
what the SP in the package does is just to Print the Package Variable value first and then set the package variable to some NOT NULL Value.When I run this same Package again with some other value, in the same session..it prints the previously set value before the setting..although in the declaration the value has been initilized to NULL ???
Please send ur feedback..
Jeet
ASKER CERTIFIED SOLUTION
Avatar of Helena Marková
Helena Marková
Flag of Slovakia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is from asktom site, I think that it is your case:

are the variables declared on top of PACKAGE BODY that is the variables that are global to a package body are also main tain state

i have :
SQL> create or replace package my_pack AS
  2  
  3  PROCEDURE P1;
  4  END;
  5  /

SQL> Create or replace package BODY my_pack AS
  2  
  3  v1 varchar2(1) := 'N';
  4  
  5  PROCEDURE P1 AS
  6  BEGIN
  7   DBMS_OUTPUT.PUT_LINE(V1);
  8   IF v1 = 'N' THEN
  9    V1 := 'Y';
 10   END IF;
 11   DBMS_OUTPUT.PUT_LINE(V1);
 12  END;
 13  END;
 14  /

SQL> EXEC MY_PACK.P1;
N
Y

PL/SQL procedure successfully completed.

SQL> EXEC MY_PACK.P1;
Y
Y

any idea why is this happening

Followup:  
any variable defined outside of a procedure/function is a global variable and maintains its state for the duration of the session.
Avatar of jeet1234
jeet1234

ASKER

Thanks Henka,
as I see..package variables are loaded only once per session,so they can only be initilized in the main program part(SP) called.
I did a test myself and understood that if multiple application calls use the same session then the Package call becomes Synchronous.the second call starts only after the 1st finishes...thus there won't be any variables taking wrong value if I initilize the variables at the start of my proc(not the package).
Regards
jeet