?
Solved

Oracle Package Variables

Posted on 2003-02-27
3
Medium Priority
?
1,346 Views
Last Modified: 2013-12-12
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
Comment
Question by:jeet1234
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
Helena Marková earned 300 total points
ID: 8039997
This is a very good site:
http://asktom.oracle.com/

Henka
0
 
LVL 22

Expert Comment

by:Helena Marková
ID: 8040019
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
 

Author Comment

by:jeet1234
ID: 8040337
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Via a live example, show how to take different types of Oracle backups using RMAN.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question