• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1351
  • Last Modified:

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
0
jeet1234
Asked:
jeet1234
  • 2
1 Solution
 
Helena Markováprogrammer-analystCommented:
This is a very good site:
http://asktom.oracle.com/

Henka
0
 
Helena Markováprogrammer-analystCommented:
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.
0
 
jeet1234Author Commented:
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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now