Global Variable in Package Specification

Hello,
I created global variable in package specification,
Is it valid for the current session or it will work for all the session.
Thanks,Kannan.K

Package varaibles are session bound, to demonstrate, a simple test:
--session 1:
SQL> select dt_test_pack.get_global from dual;
GET_GLOBAL
SQL> exec dt_test_pack.set_global(50);
PL/SQL procedure successfully completed.
SQL> select dt_test_pack.get_global from dual;
GET_GLOBAL
        50
--Session 2 at the same time
SQL> select dt_test_pack.get_global from dual;
GET_GLOBAL
SQL> exec dt_test_pack.set_global(100);
PL/SQL procedure successfully completed.
SQL> select dt_test_pack.get_global from dual;
GET_GLOBAL
       100
--Back to session 1:
SQL> exec dt_test_pack.set_global(null);
PL/SQL procedure successfully completed.
SQL> select dt_test_pack.get_global from dual;
GET_GLOBAL
--Back to session 2:
SQL> select dt_test_pack.get_global from dual;
GET_GLOBAL
       100HTH
David

Similar Messages

  • What are the Advantages & Disadvantages of Global Variable at Package Level

    Dear Expprts
    Please tell me,
    What is mean by Global Variable?
    What are the Advantages and Disadvantages of Global Variable at Package Level against Private Variable?

    HI
    GLOBAL VARIABLE UR USE ANY BLOCK IN PLSQL
    BUT LOCAL VARIABLE USED ONLY THERE THEY DECLARE.
    REGARDS
    MOHAMMADI

  • Using global variable in package

    Hi. I have created a function (Retrieve_SerialNo) which returns a variable, which I use throughout my package. I would like to assign this variable as a global variable to be used by all functions and procedures in the package. Can someone help me in the declaration of this variable as a global variable? Also, is it necessary for me to initialize this variable whenever the package executes. If yes, how would I do this?
    CREATE OR REPLACE PACKAGE BODY Supply_Item_Interface AS
    FUNCTION Retrieve_SerialNo RETURN VARCHAR2 IS
        v_serial_no VARCHAR2(20);
        CURSOR Serial_Code IS
          SELECT S.Serial_Code
            FROM Spare_Parts s, Orders r
           WHERE s.serial_code = r.serial_code;
      BEGIN
        OPEN Serial_Code;
        LOOP
          FETCH Serial_Code
            INTO v_serial_no;
          EXIT WHEN Serial_Code%NOTFOUND;
          v_serial_no := v_serial_no;
        END LOOP;
        CLOSE Serial_Code;
        RETURN v_serial_no;
      EXCEPTION
        WHEN OTHERS THEN
          RETURN NULL;
      END;

    user13415143 wrote:
    Hi. I have created a function (Retrieve_SerialNo) which returns a variable, which I use throughout my package. I would like to assign this variable as a global variable to be used by all functions and procedures in the package.All variables have scope or "visibility". A variable defined in a procedure is only visible within that procedure.
    A variable defines in a package body. is visible within that package body (i.e. procedures and functions in that package body can "see" that variable.
    A variable defined in the package definition? Well, who can see the definitions of procedures and function in a a package header/definition? Everyone else basically (other PL/SQL packages and procedures and functions). So this is also true for variables defined in the package interface. These are global variables that not only can be used by the code in that package's body, but also can be used by other packages and PL/SQL code.
    So when you create a global variable you need to decide on its scope:
    - define it in package header for global usage in all PL/SQL code
    - define it in package body for global usage within that package only
    CREATE OR REPLACE PACKAGE BODY Supply_Item_Interface AS
    ..snipped..Ugly code as there is no need to use an explicit cursor if returning a value from a single row. Also buggy code. If there are multiple rows returned by the cursor, the function returns the serial of the last random row. How does this make sense?
    This is what I would expect to see from a function like this. You pass it a unique identifier and it returns the applicable attribute (column) value for it.
    E.g.
    create or replace function GetSerialNo( orderNo number ) return number is
      serialNo number;
    begin
      select
        s.serial_code into serialNo
      from spare_parts s,
           orders o  
      where s.serial_code = o.serial_code
      and o.order_no = orderNo;
      return( serialNo );
    exception when NO_DATA_FOUND then
      return( null )
    end;Also note that there is no need to write ugly uppercase code. This is not a proper coding standard. Programming standards for all languages (ranging from C# to Java to Delphi to Visual Basic to C/C++) specify that camelcase should be used for variables and pascalcase for procedures/functions/methods. Uppercase is very seldom used and then only for constant names and compiler options/flags for example.
    Coding reserved words in uppercase? That is just plain silly - and not found in today's programming languages. Do yourself a favour and forget the idiotic standards used by some for PL/SQL and look at the standards for Java and .Net/C# - as the latter are the de facto standards for programming (and have been for the last 2 decades and more).

  • Data manager package log does not show Global variables!!

    Hello Experts,
    We are using BPC 10 sp14 Microsoft version with SQL Server 2008 R2. We are seeing an issue where datamanager package log does not show the Global variables defined in package script whereas in BPC 7.5 Global variable were visible in package log.
    Please let us know is this behavior changed in BPC 10?
    Below is the package script having Global variables and Package log not showing any of them.
    Thanks & Regards,
    Rohit
    Package Script:
    Package Log:

    Hi Ergin,
    As far as I remember it's by design...
    Vadim

  • PSP GLOBAL VARIABLE

    I have a problem in Calling a Global Variable(s) That Was Defined in Package and Must be Use in All procedures of Package.
    I Descibe My Problem in Following Steps:
    - First I Define A Global Variable In Package Body.
    - Second Initialize The Values Of Variable In One Of Procedures of Package.
    - Third Call The Initalized Variable In Another Procedure.
    - Forth The Called Varibale don't Have Correct Value
    When use in a Http Address. For Exapmple :
    http://ora-server:7778/pls/psp/main.proc1
    Note : When use PL/SQl I Don't Have Any Problem About.
    Please Assist Me in as Soon as Possible.
    Thank You

    Mansoureh,
    I think you landed in the wrong forum. This one is for Oracle HTML DB.
    Scott

  • Global variable in a package

    Hi,
    Can anyone tell me if this is possible?
    I have a table with some control values in it and want to be able to access some of these values in a package.
    In the spec of my package I want to be able to set a global variable for the value of a specific record.
    i.e. I want to be able to say something like:
    glo_value_1 := (select value_col from control_table where id_col = 1);
    I'm trying to avoid just creating a cursor that I will have to open/fetch/close for every procedure and function in my package. I'd like to be able to just set the value in the specification so that I can just refer to it as glo_value_1.
    Any ideas?
    Thanks
    Yog

    Well there is no support for scalar subquery in PL/SQL (in-line SELECT) but you could of course write a function to geth the control value based on it's id and assign the result of the function to the global, something like...
    glo_value_1 := control_value_function (1);

  • About package global variable.

    Hi All,
    Could you please anyone tell me from which Data Dictionary tables we can find to definiton of Package global variables which is declared in specification part.
    I tried in ALL_ARGUMENTS but I failed to get it.
    Thanks in advance.

    Thanks James for you reply.
    We written an application using utPLSQL framework, which is used to write unit test cases for Oralce server side programs.
    In one of our Oracle package we have been using global variable and is been referred by all the public members.
    To initailize the package global variable based on our test case we need to know the package global variables.

  • How to declare a global variable from a PL/SQL package

    Hi All,
    Using a global variable is a bad practise for all language. However, in my case, I have a PL/SQL package defines all constants, and I want to use them directly via SQL statement, for instance,
    PACKAGE my_const
    IS
         DEFAULT_ZIP_CODE CONSTANT VARCHAR2(5) := '00000';
    END;And I cannot referrence this variable from my select statement as
    SELECT my_const.DEFAULT_ZIP_CODE from dual;I have to create a function via my package, as,
    FUNCTION get_default_zip_code RETURN VARCHAR2
    IS
    BEGIN
         RETURN DEFAULT_ZIP_CODE;
    END;and
    SELECT my_const.get_default_zip_code from dual;I don't want to create functions to referrence the default varaibles. Does anyone have any clues?
    thanks
    Edited by: user4184769 on Jul 19, 2010 8:36 AM

    riedelme wrote:
    thanks for the info. Your scope explanation makes sense even though it is not intuitive to me. I think the usage of package variables should be supported by SQL (they're just values to be copied) Maybe look at it from another language's perspective. You want to use a global PL package variable in Java/C#/Delphi/VB/etc. How would you do it?
    None of these languages can crack open the data segment of a PL code unit, inspect the variables in it, and extract a value from it. Instead, it needs to be done as follows:
    Using sqlplus as the client illustrates how all these languages will need to do it:
    SQL> var value varchar2(20);
    SQL> begin
      2>     :value := SomePackage.someVar;
      3> end;
      4> /So why should SQL behave differently? It is not the same as the PL language. It is not a subset of the PL language. Yeah, PL/SQL blurs the line between these 2 languages making it very simple for us to mix their source code. But PL/SQL is SQL integrated with PL - not PL integrated with SQL. PL has tight hooks into SQL, creating cursors for you, defining bind variables, binding variables and doing the whole Oracle Call Interface bit for you.
    But SQL has no need for PL code, just as it has no need for Java code, or Delphi code or VB code. Yes, it is possible for it to call Java stored procs. As it is possible for it to call PL procs. But these are via the formal call interface of those languages - not via tight integration hooks that blur the languages and make SQL and Java, or SQL and PL, look like a single integrated source code unit.
    Thus SQL has the pretty much the same constraints in calling the PL language as other languages do. What SQL can do is use the PL engine's call interface and tell it "+execute this function and return the result of the function+".

  • Global Variable in Storage Package.

    Hi,
    I have one storage package with global variable.
    if others procedures (in package) change this variable, in other sessions, it will not have the init value.
    I need reset this global variable.
    please help.
    thanks.

    Hello
    Variables in packages are only visible to the session they are used in i.e. each session that uses the package gets it's own "copy" of the package and it's variables. If you want to share data between sessions you could look at global application contexts :
    http://download-west.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_5002.htm#sthref4478

  • Global Variables Vs Form Library Package Variables Vs DB Package Variables

    I realise this question has been asked a few times with varying degrees of answers, but I am still seeking comment/advice from others.
    I am aware of following options for retaining persistent data to share between forms.
    1. Package variables in a library that you share in a session.
    This requires usage of SHARE_LIBRARY_DATA, there is risk that this not set, then does not share data.
    2. Package variables in a database package.
    Requires round trip to DB. Is this expensive for performance?
    What about risk of DB package becoming invalid and losing state?
    3. Use global variables
    Can be tricky to manage.
    4. Use parameters
    Only one way, ie called form cannot alter value that caller can see.
    Packages are closest to OO approach in using get and set modules. Allows all variables to be managed in one location. This appears best practice.
    Forms library packages appear risky if caller does not include SHARE_LIBRARY_DATA.
    DB packages have cost of round trip to DB. Does this become expensive is have to reference many times. Also topic of DB package becoming invalid and losing state?
    Forms global variables have regular disadvantages of globals, ie not sure who may modify. Need to manage carefully. Text only
    As a second related question, for value such as current user, for performance (and maintainability) is it better to obtain this from oracle user function each time, or save somewhere (in one of options above) and use that saved value each time.

    My personal opinion:
    I like the "packaged" version with getters and setters. In general, i create a client-side package in a pll which has methods to access the value by getters and setters. With that, the "implementation" is encapsulated and doesn't really matter to the rest of your system. All modules have to access the value using the getter and setter.
    Inside the procedure i use two approaches:
    1. If its for communication purposes between different forms i use globals, which are filled or extracted in the getter and setter (see this http://andreas.weiden.orcl.over-blog.de/article-28180655.html )
    2. If its for someother purpose where the value should be "session persistent" i use a database package with getters and setters, which are called from the client-side package getter and setter. If the value is quite "constant" throughout the session, i read the value once at initialization code of the client-side package and the getter just returns that "cached" value
    Hope this helps.

  • Program units (Package) as global variable

    Hi all,
    Report 10g, generate PDF on the web.
    I need to manage some informations as rowtype.
    So, I defined a program unit as Package Spec VAR and defined v1 tablename%rowtype. When fired the trigger After Parameter Form run a procedure that populate the VAR.v1 and so I can use this information inside the column formula or format trigger without read the table many times.
    I try on client / server and all is ok.
    I try on the web and the package spec not work good. Exist some rule or bug about it?
    I try to move the package on the DB as Stored Procedure and so the report is ok.
    Thank you in advance.

    But in report builder is it possible to use global variable define as rowtype?
    I have some doubts about it.
    About my problem I want add an example to understand better the situation:
    As program unit I defined:
    PACKAGE VAR IS
    vTab0001 tab0001%rowtype;
    END;
    FUNCTION TAB0001_GET (pCom number) RETURN tab0001%rowtype IS
    vTab0001rec tab0001%rowtype;
    BEGIN
    Select *
    into vTab0001rec
    from tab0001
    where t0001soc = pCom;
    return (vTab0001rec);
    Exception when others Then
         return (null);
    END;
    About the After Parameter Form trigger:
    var.vTab0001 := tab0001_get(:company_code);
    With the srw.message(12345, var.vTab0001.t0001soc) check the value in all the report.
    In client/server all it is ok.
    In web I received the error
    REP-0069: Internal error
    REP-57054: In-process job terminated:Terminated with error:
    REP-1418: 'cf_1formula': Passed null arguments to SRW.MESSAGE.
    So, I have the evidence that the var.vTab0001.t0001soc is null.
    Can you help me to find a way?
    Is there someone that had this case in report builder?

  • How to auto create a global variable with specific variable name in a global vi ?

    how to auto create a global variable with specific variable name in a global vi using lv ? Because i need to add a lot of global variable in this global vi. But you know, if  i manually add them , it will be a much time-costing work. So i want to use someway to auto generate ? Can i ?? Thanks a lot !

    Hi
    what aartjan is saying is the way for you. but you can develop an utility which will actually help you create global variables. To get the details on this just have a look at VI Scripting section on LAVA forum.
    But i would like you to suggest few things
    1. If your programs have so many global variables (Thats why u want utility) then you should take out some time to read about LabVIEW design patterns. I think if programmer follows these practicess he dont need a single global variable.
    2. Their are some other ways to achieve similar functionality as of global variables (Uninitialized Shift Registers, Single Element Qs and so on) but they are much faster than global variables.
    I am Attaching Whatever Resources i am having I will also attach the template of the design pattern i generaly use in short duration
    Message Edited by Tushar Jambhekar on 10-06-2005 07:33 PM
    Message Edited by Tushar Jambhekar on 10-06-2005 07:36 PM
    Tushar Jambhekar
    [email protected]
    Jambhekar Automation Solutions
    LabVIEW Consultancy, LabVIEW Training
    Rent a LabVIEW Developer, My Blog
    Attachments:
    LabVIEWDesignPatterns.zip ‏1505 KB
    Large_Code_Implementation.zip ‏522 KB
    Database Tests.zip ‏868 KB

  • PL/SQL package global variable in Dev. 6i and newer....

    Hi,
    In db packages , the use of global variable is an appropriate method to keep the value it contains globally... without the danger of being overriden by other session....(as for each session , there is a 'private' section in memory(library cache)).
    Is the above also true to pl/sql packaged global variables kept at client's side(forms/reports)...????
    Thanks,
    Sim

    db-package variables are global to your session
    forms globals are global to your forms application
    In one case you have trouble: When you start a new forms via open_form (, new session, ) then your db-globals are global in that new session, while your forms globals are the same in all forms of the actual forms - session

  • Substitiute for Global variable

    i have a doubt if we can use anything other than a Global variable like:-
    :global.<var_name>
    for a variable i define at the form level, say 'When-new-form-instance' trigger and use it at block & item level.
    In a big application, there is a doubt of using a Global variable twice.
    Regards.

    Hi,
    Decalre a variable in an package specification and use that for your purpose.
    Global variables are good and bad at the same time. Once declared the live for the whole session. Each of them occupy 255 bytes of memory, so it's bad practise to use them heavily. Instead you can use the same variable again and again, but be aware: Since they keep their value they could lead to undesired behaviour unless you are careful and null's them (or give them a default value) each time you have used them. Often I capture their value in the pre-form trigger, store the value in a package variable within the form, and then give the global a value of '-1' (which is my default).
    /Michael

  • Unit Testing and APEX Global Variables

    We've recently started to unit test our database level PL/SQL business logic.
    As such we have a need to be able to simulate or provide output from PL/SQL APEX components in order to facilitate testing of these components.
    Some of the most obvious portions that need simulation are:
    1. The existence of a session
    2. The current application ID
    3. The current page ID.
    We currently handle requirement #1 by using apex_040100.wwv_flow_session.create_new
    We handle 2 and 3 using the apex_application.g_flow_id and g_flow_step_id global variables.
    I'm just wondering, how safe is it for us to use wwv_flow_session.create_new to simulate the creation of a session at testing time for those things which need a session?
    I've also noticed that there are apex_application.get_application_id and apex_application.get_page_id functions whose output is not tied to the global variables (at least in our current version).
    Is it safe for us to expect that we can set these global variables for use in testing or is apex moving to get_application_id and get_page_id functions away from global variables?
    Will there be corresponding set_application_id and set_page_id functions in the future?
    Sorry for the question bomb. Thanks for any help.

    My first question would be why do you need to establish a session to test your PL/SQL?
    wwv_flow_session is a package internal to APEX, and you should probably leave it be.
    The get_application_id procedure you refer to is in apex_application_install, which is used for scripting installation of applications - not get/set of page ID like you're describing.
    If you're uncomfortable using apex_application.g_flow_id, you can use v('APP_ID') or preferably pass the app_id/page_id as parameters to your procedures.
    Your question seems to have a few unknowns, so that's the best I can describe.
    Scott

Maybe you are looking for

  • How to programmatically set initial password when a user is created in OID

    We are using the odihragent synchronization process to automatically create users in OID when an employee record is created. We would like to set the initial password for the newly created user to their last name + the last 4 digits of their SSN. The

  • I lost one of my email accounts on my phone when i updated it yesterday.  How do i reinstall it.

        had 2 email accounts in mail on my iphone5     Updated my iphone yesterday      Lost 1 email account       Tried to reinstall.  i can send mail but can't receive it. What's the trick?

  • Help with AExp and airtunes - setting up network

    So I've had one of the original airport expresses for a few years, and in my previous house I used it in WDS remote mode, using the ethernet jack as an internet connection for a..ahem...well known gaming console, and the audio jack for airtunes. In m

  • Unable to insert JRadio in JTable.

    Hi All, I'am very new to swing development and working on JTable which should contain 4 columns (Index,RadioButton,Device Name and Device Number).The rows are added dynamically.I have written classes MyTableModel, MyTableRadioButtonRenderer and MyTab

  • Clock & Calculator missing?

    I notice unlike the iPod Touch there isn't a clock or a calculator built in app on the iPad 3.  Was there a reason to exclude these from the iPad and can they be downloaded from somewhere, not necessarily the calculator but I quite like the clock app