Global Variables across sessions in PL/SQL package Specification

Hi,
Is there a way I can share a variable value across sessions that doesnot affect by Commit/rollback.
The value would be set by one session and is visible across sessions, until it is set to another value by another/same session, and the new value is visible across.

V$Session is not granted to the user executing this. So, had to go with the context. Finally could resolve with the following code.
Run by DBA
create or replace context ctx1 using USER_procowner.pkg_global accessed globally;
grant execute on dbms_session to USER_procowner;
Run by user_procowner
create or replace package user_procowner.pkg_global AS
procedure set_lock(in_val IN VARCHAR2);
Function get_lock RETURN VARCHAR2;
end pkg_global;
create or replace package body user_procowner.pkg_global AS
procedure set_lock(in_val IN VARCHAR2) IS
begin
dbms_session.set_context('ctx1','var1',in_val);
end;
Function get_lock RETURN VARCHAR2 IS
begin
return (Sys_context('ctx1','var1'));
end;
end pkg_global;
grant execute on pkg_global to user_procuser;
exec user_procowner.pkg_global.set_lock('Y')
select user_procowner.pkg_global.get_lock Lock from dual;
LOCK
Y
exec user_procowner.pkg_global.set_lock('N')
select user_procowner.pkg_global.get_lock Lock from dual;
LOCK
N
The current value of var1 is visible across sessions using user_procowner.pkg_global.get_lock.
Thanks to all contributors.

Similar Messages

  • How to Print the Value of a variable inside a PL/SQL package

    Hi Friends,
    Here is my Scenario
    I have a PL/SQL Package. Let us call it Baseline Package.
    This Package includes a dynamically built merge Statement.
    Execute Immediate v_merge_query.
    I have a procedure which replaces which few Keywords from the Package Text and Creates a new one depending on Inputs I provide. (This is something like a Code generator)
    Now while Creating the new package, I need to print the Value of v_merge_query.... I Need s Static Query to be Printed inside the new package and not a dynamic query.
    My Question is "Is there a way to print the value of the variable inside a different PL/SQL package?
    Thanks in Advance,
    Mohit

    Print where?
    That PL/SQL code is server-side code. It runs in an Oracle server process.
    That server process does not have a keyboard. Or a screen/monitor. Or display canvas. Or an attached printer.
    That server process is incapable of "printing" as that is not its job or responsibility and not part of its environment.
    What is can do is record data for the client to look at afterwards. This can be done using static PL/SQL session variables. Or a SQL table.
    The former is done by DBMS_OUTPUT - a very primitive interface for writing text into a static PL/SQL string array. That btw resides in expensive private process server memory. The client can query the array after a database call and render the contents.
    PS. Also keep in mind that bind variables are critical for performance and server robustness - especially when (ab)using dynamic SQL.

  • 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

  • PI Global Variables

    I have been looking for ways to support global variables (across maps, not within a single map) and cannot find anything.
    My scenario is a synchronous RFC out of R3, through PI, and out to a vendor's product lookup service...all synchronous.  The issue is that I need to log values from the RFC request as well as values from the vendor response.
    I can get the process working with a sync/async bridge in a BPM (the async part being to write out vendor response to the log file).  What I need is some way to store RFC request values and map them into my log file too.
    Unless there is some Global variable method that spans across an entire process, I figure I need to do something special in the BPM.  Can I achieve this by creating a split/copy of my request message, sending one out to the vendor and holding the other in a BPM wait of some sort.  Then when the response comes back, split/copy it also and let one copy respond to SAP and the other merge up with the waiting request?  Or something like this? 
    Thanks for any suggestions.
    Keith

    Hi Keith,
    I think you can achieve your requirement using a combination of Lookup & BPM (Sync Async bridge)  techniques. May be you can try the following;
    Integration process design:
    START
    ^^
    ReceiveStep(Open SyncAsyncBridge)
    ^^
    Transformation (MultiMapping with lookup)
    ^^
    SendStep(Send RFC Resp &Close SyncAsyncBridge)
    ^^
    SendStep(Send Log message)
    ^^
    STOP
    Details:
    Step1: Use Receive step to receive the sync RFC message and ope n S/A bridge.
    Step2: In Mapping (Transformation step) use Mapping lookups (RFC/DB/SOAP) to get the Vendor response and in same mapping generate both the Log message and RFC response as output messages (Multi-Mapping)
    Step3:Send RFC Response message and close S/A bridge
    Step4:Send Log message
    Hope this helps.
    Regards,
    Ananth

  • Programmatically select global variable object

    Hello all.
    I have a rookie question that may have an easy answer (or perhaps you can direct me to a different method which is fine too).  I’m using a global variable in an instance where it’s controlled by a parent VI and read by multiple children VIs.  The global variable contains Boolean switches, each with a specific name.  
    If possible, I’d like to make the ‘child VI’ more generic and programmatically flexible so that I don’t have unique children.  That way, instead of four children, I just have one (makes debugging easier).  Here’s the crux of my question:  selecting which object is assigned to the global variable on the block diagram is done by clicking on it with the mouse – can I instead do that programmatically?
    More specifically, when using the global in children VIs (as instructed in the “Creating Global Variables” section of the help files), you can select the global vi and add it to your block diagram.  The next step is to select the front panel object to associate the placed variable with the proper data (you do this by mouse clicking the node you just created – see the attached image).  My question is, can I select the object associated with the placed node programmatically instead of needing to mouse click on it?
    Cheers!
    Attachments:
    ForumEX files.zip ‏31 KB

    Steve Chandler wrote:
    There is a better way of doing this as the others have already pointed out.
    Even Single Process Shared Variables with their API Interface would be better as Globals:
    Using this VI to read the variables gives you the ability to reference them with a string (Link to Variable). You may have to add an additional variable in future versions of your code, where you just need to add the new variable to the project and pass the string to the VI without changing the code. Single Process Shared Variables are based on Global Variables, which are usually just a bit faster. Single Process Variables can easily be converted to network variables.
    However, I agree with Damien that Data Value References would probably be the best sulution.
    Btw, there is a good KB talking about Globals: Are LabVIEW Global Variables good or bad, and when is it ok to use them?
    Christian

  • 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

  • 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 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

  • 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

  • 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).

  • 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);

  • 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

  • Setting global variable to be used in a SQL task

    I am trying to create a simple SSIS package to be used in the SQL Task
    The SQLStatement is
    Update dbo.Users
    set FirstName = ?
    where UserID = 2
    Added a parameter mapping for User::strDataString
    From the data manager dynamic script, I included following code to prompt for the value and set to the global variable and then call the excecute SQL task.
    PROMPT(TEXT,%strData%,"Enter value",,"")
    GLOBAL(@[User::strDataString],%strData%)
    TASK(Execute SQL Task,,)
    When the check the database, the table is getting updated only with the default value of the strDataString but not with the value entered in BPC.
    Am I missing any link?
    Thanks
    Omkar
    Edited by: yomkar on Mar 17, 2010 1:13 PM

    Hello,
    on which version of BPC are you running ?
    Can you try to make all your SSIS variables upper case, it helped me on earlier versions of BPC.
    Be aware too that if you have an instruction like GLOBAL(STR,some_value), BPC will do a string replacement within the MODIFYSCRIPT variable  : "STR" -> "some_value".
    for example :
    GLOBAL(STR,some_value)
    TASK(STR TSK,....) will be replaced by TASK(some_value, ....).
    Vladimir.

  • 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.

  • Changing Variable values and saving it across sessions.

    Hi,
    I've have an requirement like counting the number of times a form is opened and number of times a button is clicked.For this I tried to use global variables.I tried to increment the value of the variable each time a form is opened or a button is clicked.
    opencount.value += 1;
    But it didnt work for me.I tried to hardcode a value like
    opencount.value = 5;
    Even this is also not working.Do I need change any settings or extend rights.Is it possible to save the values that are persistent across the sessions.
    Please help

    I have another apporach using an extras object.
    What you is a script object 'Actions' with this script, to create a counter in the extras object in any form object.
    function initOpenCounter(targetObject) {
        if (targetObject.extras.nodes.namedItem("OpenCounter") === null) {
            targetObject.extras.nodes.append(xfa.form.createNode("extras", "OpenCounter"));
            targetObject.extras.OpenCounter.nodes.append(xfa.form.createNode("integer", "state"));
            while (targetObject.extras.OpenCounter.nodes.length > 0) {
                targetObject.extras.OpenCounter.nodes.remove(targetObject.extras.OpenCounter.nodes.item(t argetObject.extras.OpenCounter.nodes.length - 1));
            var newState = xfa.form.createNode("integer", "OpenCounter");
            newState.value = 0;
            targetObject.extras.OpenCounter.nodes.append(newState);
    Then you need another script, to call the function in the script object and raise the counter, when the form opens.
    I used a floating field in a text on a master pager and put this script into its initialize event.
    Actions.initOpenCounter(this);
    var cCount = parseInt(this.extras.OpenCounter.nodes.item(0).value, 10);
              cCount += 1;
    this.extras.OpenCounter.nodes.item(0).value = cCount;
    this.rawValue = cCount;
    Here's a sample form with an open and save counter.
    https://acrobat.com/#d=C90OHrJKx52LHrtbtahWzQ

Maybe you are looking for

  • Installing Adobe Photoshop Elements 10 without Discs

    I recently purchased Adobe Photoshop Elements 10 on amazon.com.  The product was shipped to me with installl discs.  The problem is that my Mac does not have a DVD drive.  Is there a way to install the product online using the serial numbers on the p

  • Table name for purchase order delivery fields

    Hi Gurus, Can you please tell me the name of the tables and the joining condition for purchase order delivery details like Name, street , city, postal code, address detail and the joining condition? Regards MD. SAMY

  • Multi-monitor viewing

    Suggestions or comments for viewing multiple pages horizontally across multiple monitors? Would like to setup 2-3, maybe four pages horizontally.

  • Import of RAW (NEF) files from Nikon D 90

    Hi there: > I am new to lightroom and just got a 30 days trial version. I desperately try to import directly RAW (NEF) files into lightroom 2. I have downloaded Adobes latest RAW converter. I also checked all available support areas (hope at least I

  • My itouch 4 gen wont connect to the 'network' so it cant download the new airplay or the update

    when ever i conect it to my computer trying to get airplay and the download it says something like 'you are not conected to the network please conect to the network and try again' but i dont know what the 'network' is. i work on a pc is that a proble