Accessing a Global package variable Via Select

Hi All,
I want to access a global variable i.e package global variable through a select query. Is this possible or not possible. Please share some inputs on this.
Thanks

Just to clarify that you can reference the global variable if your SQL is itself within PLSQL. It will be bound in.
CREATE OR REPLACE PACKAGE p1
AS
  my_global NUMBER := 1;
  FUNCTION f_get_my_global
  RETURN NUMBER;
  PROCEDURE p_do_something;
END;
CREATE OR REPLACE PACKAGE BODY p1
AS
  FUNCTION f_get_my_global
  RETURN NUMBER
  AS
  BEGIN
     RETURN my_global;
  END;
  PROCEDURE p_do_something
  AS
    l1 NUMBER;
  BEGIN
    SELECT /*+ find_me */
           my_global
    INTO   l1
    FROM   DUAL;
  END;
END;
SQL>  exec p1.p_do_something;
PL/SQL procedure successfully completed.
SQL> select sql_text from v$sql where sql_text like '%find_me%';
SQL_TEXT
SELECT /*+ find_me */ :B1 FROM DUAL
SQL>

Similar Messages

  • ORA-20001: Unauthorized access (security group package variable not set).

    I'm creating an app that uses APEX authentication and features self-registration (working) and forgot password (not working) forms.
    My forgot password is public (requires no authentication). The user provides username and secret answer, which are validated, then provides the new password. I attempt to use htmldb_util.reset_pw to reset the user's password, but it's not working.
    I have a process on the new password page calling a PL/SQL anonymous block that looks like this (see below), where P16_ITEM1 = username and P18_ITEM1 = new password.
    BEGIN
    apex_040000.htmldb_util.reset_pw( V('P16_ITEM1'), V('P18_ITEM1') );
    END;
    I also don't know how to send accurate success/failure messages from such PL/SQL block back to APEX, but that's a separate issue I guess.
    Anyway, when testing via SQL Developer as the user with APEX_ADMINISTRATOR_ROLE, I get the following error:
    ORA-20001: Unauthorized access (security group package variable not set).
    ORA-06512: at "APEX_040000.WWV_FLOW_FND_USER_API", line 22
    ORA-06512: at "APEX_040000.WWV_FLOW_FND_USER_API", line 1220
    ORA-06512: at "APEX_040000.HTMLDB_UTIL", line 1253
    ORA-06512: at line 8
    I've searched previous threads and tried different suggestions with no luck.
    I'm on Oracle DB XE 11g and APEX 4.x.
    Any help will be appreciated. Thanks,
    Alex.

    Anyway, when testing via SQL Developer as the user with APEX_ADMINISTRATOR_ROLE, I get the following error:
    ORA-20001: Unauthorized access (security group package variable not set).When running code outside Apex that depends on the Apex security group being set, run the following before your own code:
    wwv_flow_api.set_security_group_id(apex_util.find_security_group_id('YOUR_SCHEMA_NAME'));Google "wwv_flow_api.set_security_group_id" for more details, such as this blog post:
    http://www.easyapex.com/index.php?p=502
    - Morten
    http://ora-00001.blogspot.com

  • Global package variable for the current rendering item

    I like to define a generic plsql function which handles all the page 0 item conditions. I will place this function call in all page 0 item conditions.
    Now I need a global (htmldb_application) package variable which I can use to identify for which item condition the function is executed.
    Which global variable can I use for this purpose or is there an other way to do this.
    I dont't want to give the the item names hardcode as argument of the function.

    Scott,
    I will try to clarify my question.
    I have lot of page 0 items.
    I like to give every item the same plsql condition such as htmldb_pck.show_item or
    htmldb_pck.show_item('#CURRENT_ITEM#').
    In my own htmldb_pck.show_item function I have all the display coding of the generic items.
    My problem is that I have to know from which item the function is called.
    Thanks,
    Fred.
    May be this is something for an enhancement. Not only for the items, but also for the buttons, tabs, tab sets and report columns. So you know in generic pl/sql from which object the pl/sql is called.

  • Accessing Tomcat Global Environment Variables

    Hello,
    I have tried to access Tomcat 5.0 (xx) Global Environment variables.
    I have the Integer simpleValue defined in the Tomcat Administrators panel under "Environment Entries"
    Here's my code:
    Context initContext = new InitialContext();
    Context envContext = (Context)initContext.lookup("java:comp/env");
    Integer i = (Integer)e.get("simpleValue");
    I have also tried and infiinite variation of this with no success (Accessing the Initialcontext directly)
    The Tomcat docs at: http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-resources-howto.html
    says:
    "<Environment> - Configure names and values for scalar environment entries that will be exposed to the web application through the JNDI InitialContext (equivalent to the inclusion of an <env-entry> element in the web application deployment "
    PLEASE HELP !!!
    Geir Ove

    This is a Tomcat bug. See http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14228.

  • AD Search plus access to task sequence variables via powershell.

    Hi,
    I would like to an Active Directory search in a SCCM task sequence.
    Now there are two ways I can do this run the powershell script
    as a domain user - in the task sequence step.
    Or do something fancy in the script itself so the task sequence step
    runs as system then does a kind of connect as to do the AD search.
    The reason I am asking this is I want to know if the task sequence
    variables are available of I run the powershell script as user
    account from the task sequence UI.
    Or can I only get at them if I am running them as the system context.
    Thanks,
    Ward

    First, answer to your question: if you run an action as a different user in a task sequence (which can only be done after you leave WinPE), you lose the ability to read the task sequence variables. You'll get empty strings for every variable you query.
    Now there are several ways of getting this accomplished and it all depends on what stage of the task sequence you want to invoke something like this/what you want to do in AD.
    If just want to query AD then, by default, you don't need any special rights as any domain user can do it.
    If you want to modify something in AD then you need to be a bit more creative.
      1. If you want to run this script after the computer has joined the domain, you don't need to mess around with permissions, as any network actions will be run using the computer object on the network. As far as AD is concerned it will use ComputerName$
    account. Though obviously you'll only have read rights.
      2. Use the network access account credentials, the username/password for the account are saved onto task sequence variables so you can easily read it. The script itself would still run under the system context, but when you establish a connection
    to AD you pass the username/password of the user to connect as. Again, you'd only have read rights.
      3. If you want to modify something in AD and the task sequence has already left WinPE, then you can use the 'run as a different user' option in the 'run command' action in the SCCM task sequence. This will force the whole script to run under the context
    of the user you specified, which obviously gives you whatever rights you want, including ability to modify something in AD, but you completely lose access to task sequence variables. If you try to query any of them you just get an empty string. A way around
    this is to make the variables you know you will need as part of your script in parameters. So for example you call your script as: MyScript.ps1 -MP %_SMSTSMP% to pass the variable _SMSTSMP to your script as a parameter. You can only specify 'run as a different
    user' if the task sequence is not in WinPE though.
      4. You could use a slight variation of option 2 if you need to modify AD. Instead of using the NAA account use the username/password of an account you specify. The action still runs under system context, but the connection to AD runs with the account
    you specify. As a result, this also works in WinPE, and you have no problems accessing task sequence variables. The only problem with this one though... is how to safely pass the credentials over, and that's a big tricky problem.
    As you can see, there's several ways of getting things done, but they all have caveats :)
    Hope this helps.

  • Error trying to run SSIS Package via SQL Server Agent: DTExec: Could not set \Package.Variables[User::VarObjectDataSet].Properties[Value] value to System.Object

    Situation:
    SSIS Package designed in SQL Server 2012 - SQL Server Data Tools
    Windows 7 - 64 bit.
    The package (32 bit) extracts data from a SQL Server db to an Excel Output file, via an OLE DB connection.
    It uses 3 package variables:
    *) SQLCommand (String) to specify the SQL Statement to be executed by the package
    Property path: \Package.Variables[User::ExcelOutputFile].Properties[Value]
    Value: f:\Output Data.xls
    *) EXCELOutputFIle (String) to specify path and filename of the Excel output file
    Property path: \Package.Variables[User::SQLCommand].Properties[Value]
    Value: select * from CartOrder
    *) VarObjectDataSet (Object) to hold the data returned by SQL Server)
    Property path: \Package.Variables[User::VarObjectDataSet].Properties[Value]
    Value: System.Object
    It consists out of 2 components:
    *) Execute SQL Task: executes the SQL Statement passed on via a package variable. The resultng rows are stored in the package variable VarObjectDataSet
    *) Script Task: creates the physical output file and iterates VarObjectDataSet to populate the Excel file.
    Outcome and issue:The package runs perfectly fine both in SQL Server Data Tools itself and in DTEXECUI.
    However, whenever I run it via SQL Server Agent (with 32 bit runtime option set), it returns the errror message below.
    This package contains 3 package variables but the error stating that a package variable can not be set, pops up for the VarObjectDataSet only.  This makes me wonder if it is uberhaupt possible to set the value of a package variable
    of type Object.
    Can anybody help me on this please ?
    Message
    Executed as user: NT Service\SQLSERVERAGENT. Microsoft (R) SQL Server Execute Package Utility  Version 11.0.2100.60 for 32-bit  Copyright (C) Microsoft Corporation. All rights reserved.    Started:  6:40:20 PM  DTExec: Could
    not set \Package.Variables[User::VarObjectDataSet].Properties[Value] value to System.Object.  Started:  6:40:20 PM  Finished: 6:40:21 PM  Elapsed:  0.281 seconds.  The package execution failed.  The step failed.
    Thank you very much in advance
    Jurgen

    Hi Visakh,
    thank you for your reply.
    So, judging by your reply, not all package variables used inside a package need to be set a value for when run in DTEXEC ?
    I already tried that but my package ended up in error (something to do with "... invocation ...." and that error is anything but clearly documented. Judging by the error message itself, it looks like it could be just about anything. that is why I asked my
    first question about the object type package variable.
    Now, I will remove it from the 'set values' list and try another go cracking the unclear error-message " ... invocation ...". Does an error message about " ... invocation ..." ring any bells, now that we are talking about it here ?
    Thx in advance
    Jurgen
    Yes exactly
    You need to set values only forthem which needs to be controlled from outside the package
    Any variable which gets its value through expression set inside package or through a query inside execute sql task/script task can be ignored from DTExec
    Ok I've seen the invocation error mostly inside script task. This may be because some error inside script written in script task. If it appeared after you removed the variable then it may because some reference of variable existing within script task.
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

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

  • Accessing Package variables

    Hi friends..
    I have to access the value of a variable which is declared public in the package in a select statement
    i tried this way
    select package_name.variable_name from dual; which is not working.
    I had a alternate solution..Declare a function in the package to make the value return by a function and access the function in the select statement.
    Is this approach correct or do i have any other alternatives?
    Thanks,
    Dwarak.k

    The reason that this does not work is that the SQL Engine cannot simply read a value residing in the package state in the PL/SQL Engine. SQL has no means to access (read or write) that value - only the PL/SQL Engine has.
    The SQL engine can however call PL/SQL functions - and such a function running in PL/SQL can access whatever it likes within the PL/SQL context.
    Is this a good idea, using package state for static variables from a SQL perspective?
    My initial reaction is that it's not a good idea. Primarily because the majority of database clients today are stateless clients - even within the J2EE context.
    For example, your Java Application Server creates a pool of 10 connections to Oracle. User John connects and is serviced by pool process 5. A PL/SQL state variable is set in that Oracle connection. The very next request from user John is serviced by pool process 9 - as pool process 5 is busy servicing Scott.
    Just who will be reading whose static PL/SQL state variables?
    PL/SQL static/state variables should be limited for use by PL/SQL only. E.g. something that I always do is to create a package called CONST (after the constants declaration in Pascal/Delphi) and define all my PL/SQL statics there.
    The PL/SQL code must be written being aware that each new call can be made from another front-end user (resetting session state becomes important).
    For other constants... - that is why lookup and application configuration tables should be created. Single copy of the data. Concurrency catered for. Data integrity provided.

  • Accessing a packaged variable through db link

    How do I access a packaged variable remotely? (Syntax)

    You cannot do that:
    SQL> conn xx/xx@xx
    Connected.
    SQL> create package p is
      2   a number;
      3  end;
      4  /
    Package created.
    SQL> conn yy/yy@yy
    Connected.
    SQL> desc p@yy
    SQL> set serveroutput on
    SQL> create synonym p1 for p@xx;
    Synonym created.
    SQL> desc p1;
    SQL> begin
      2    p1.a := 1;
      3    dbms_output.put_line(p.a);
      4  end;
      5  /
      p1.a := 1;
    ERROR at line 2:
    ORA-06550: line 2, column 6:
    PLS-00512: Implementation Restriction: 'P1.A': Cannot directly access remote package variable or cursor
    ORA-06550: line 2, column 3:
    PL/SQL: Statement ignoredInstead you should access these variables via functions and/or procedures. In following example I've created the private variable in package p but this doesn't matter whether it is private or public.
    SQL> conn xx/xx@xx
    SQL> create or replace package p is
    2 procedure set_a (v in number);
    3 function get_a return number;
    4 end;
    5 /
    Package created.
    SQL> ed
    Wrote file afiedt.buf
    1 create or replace package body p is
    2 a number;
    3 procedure set_a (v in number) is
    4 begin
    5 a := v;
    6 end;
    7 function get_a return number is
    8 begin
    9 return a;
    10 end;
    11* end;
    SQL> /
    Package body created.
    SQL> conn yy/yy@yy
    Connected.
    SQL> set serveroutput on
    SQL> desc p1
    FUNCTION GET_A RETURNS NUMBER
    PROCEDURE SET_A
    Argument Name Type In/Out Default?
    V NUMBER IN
    SQL> ed
    Wrote file afiedt.buf
    1 begin
    2 p1.set_a(1);
    3 dbms_output.put_line(p1.get_a);
    4* end;
    SQL> /
    1
    PL/SQL procedure successfully completed.
    Gints Plivna
    http://www.gplivna.eu

  • How can I run two different vi's in same project which are accessing same global variable with out effecting the speed of the execution of both the vi's

    Hi
    I have build an Labview project with FPGA target .  I have configured an FPGA VI and an host Vi to acquire data and logged the data to a file and stored the latest data in a global variable simultanously. I have configured one more VI in the same project  to access the global variable.  I have build a dll to access both the VI as functions in LabWindows/CVI code.  My task in CVI is to update configured GUI with latest data periodically and run the  host VI continously for a long time and log the data to a file. GUI should update for every one second with latest data for this I am using the second VI in which I am accessing the global varibale in which the latest data has been stored in host VI.

    Duplicate Post (go here)

  • Report cannot access pl/sql table variable defined in Package Spec.

    Hi,
    I've created a package spec called pkg_report with a PL/SQL table variable defined called body_text_table. When I tried to compile the following code under the Before Report trigger:
    :desc := pkg_report.body_text_table(1);
    Oracle gave me the following error:
    Implementation Restriction: 'PKG_REPORT.BODY_TEXT_TABLE': Cannot directly access remote package variable or cursor.
    Does anyone have any idea about this error? Thank you for your time at looking at it.
    Regards,
    John

    You cannot directly access the package variable in a database package. The work around is to create a set_variable and get_variable wrapper function in the package body. See Metalink note 105838.1 for more info.
    A simple example:
    create or replace package my_package as
      my_var     number;
      function   get_variable return number ;
      procedure  set_variable (p_value in number) ;
    end ;
    create or replace package body my_package as
      function get_variable return number is
      begin
        return my_var;
      end ;
      procedure set_variable(p_value in number) is
      begin
        my_var := p_value ;
      end ;
    end;

  • Accessing database package variables from Forms

    I have a database package that populates a table of values, i.e.
    type t_route_list is table of rt_route.RTR_ID%type;
    route_list t_route_list
    route_list gets populated by a package function and I want to access route_list in the Form.
    While I can access other package variables by writing a function that returns the variable, Forms doesnt seem to like functions that return a user defined datatype as above. I have also tried using a procedure with an OUT param instead of a function but it also fails with same error.
    i.e.
    declare
    v_route_list pkg_bulk_route_replace.t_route_list;
    begin
    pkg_bulk_route_replace.init;
    pkg_bulk_route_replace.get_route_list(v_route_list);
    message(v_route_list(1));
    end;
    This will not compile, but removing the index (1) from the last line makes it compile but crash with ORA-0600.
    The code above with message replaced with dbms_out.put_line works fine on TOAD.
    So my question is......
    Can my database package return a plsql table to a form and if so, how?!

    Actually I've got this to work now!
    Thde main culprit appears to be a difference in the version of sql or pl/sql used on forms (version 5) and the database (8.1.7).
    I had defined my table as a nested table. By redefining this as a indexed table, simply by adding on 'index by binary_integer' on my server package, I am suddenly able to access the elements of the table on my form. Fortunately this did not break the server code either - the table was populated using bulk collect and that still works.
    Still got a bit of coding to do, but things are looking up now.

  • No access on global variables in sequence calls

    Hello,
    I have the following problem:
    I don't have access on global variables (Fileglobals.xx) in subsequences.
    I had access on the global variables until I add a big array to the global variables.
    Is this the reason for that strange behavior?
    thank you for your help
    Samuel

    Hello Ray,
    1)
    I had two string arrays with: array1[0....11][0...800], array2[0...6][0.....400]
    until this everything was ok
    then I increased the array1 to array1[0....11][0...1200]
    from this point I had the problem
    2)
    No the subsequences are in the same sequence file
    3)
    I am using teststand 3.1
    would it be better for this probelm to use teststand 3.5?
    Thank You for your help
    regards
    Samuel

  • Globals vs package variables

    We want to get rid of the Globals we currently use in forms. Thought of creating a package with package variables and setting these from the form. We do not really want to have to create a set and get function for each variable we create.
    I wanted to be able to pass the variable name to a function to set it or get it. This would be ok using a library in forms and using the COPY and NAME_IN built ins but we want to use a pl/sql package and these are not supported there .
    Any suggestions please.

    If you want an abstractable variable mechanism then you can do something like:
    1) Create a Record type which has two columns - key and value
    2) Create a PL/SQL Table of records of this type
    3) Write routines to get and put into this table based on the Key value.
    So you have a single array of global values which can be referenced using string keys (which of course can themselves be variables or constructed at runtime)

  • Forms 9i accessing package variables

    I created a package in my sql session which contains only variables. When I connect to the database through Oracle Forms and try to access these variables in a trigger I receive the error "Cannot directly access remote package variables or cursor" How can I access these variables from within a forms module?

    You cannot access package variable or constants directly from a remote PL/SQL client. Only PL/SQL running on the server can access these. You need to implement get and set methods in the package.

Maybe you are looking for

  • Simple script to get battery charge and time remaining...

    Here's something I threw together last night, to report on the battery at the command line.  It uses /proc/acpi/battery.  My battery is C11F, just substitude your own. It takes (remaining capacity) / (design capacity) to get the percent left, and it

  • Data Log File Refnum Type Def Bug??

    Hello, I just found some quirky behaviour (LV 7.1.1): 1. In the attached LLB, open "RefnumVI.vi" 2. Select the Data Log File Refnum control and open it for editing (Edit - Customize Control ... from the menu) 3. Close "RefnumVI.vi" but leave "Refnum.

  • Problem with air and .exe

    Hello  everyone! I have a very big problem! has developed a game in flash with as3 CS4. is divided into 3 file .fla 1.fla 2.fla and 3.fla 1 call 2 , 2 call 3 uses an XML file to  store the scores. When i public the file  .air, when i install the .air

  • Duplicate title tags in soft repeat region google

    hello, i have a page that has a soft repeat region on it that gives the following link /mypage.asp?wee=191&tfm_order=ASC&tfm_orderby=dcountry_usr My question is. In google Dashboard > Diagnostics > Content analysis the above link is reported to have

  • Huge speed drop and connection problem when answer...

    About 2 days ago my internet speed dropped hugely and it's almost now unuseable.  I've run a speed test and the results are below. Any idea on what to do to get this resolved? Also, every time I answer a call or disconnect a call the broadband connec