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+".

Similar Messages

  • How can I handle global variables from different DLLs created based on VIs that access those variables

    My goal is to break apart an entirely LabView created application so I can still use parts of it (builded as Shared DLLs upon on some VIs) in my new .Net application. My problem is that some others VIs (that I am not intending using) are changing those global variables (in the natural data flow of the application).  I could , of course, send the values of those global variables as parameters, but I don't know how should I pass those data types (and their size)... There are some clusters there...
    Any help is well appreciated

    vulpe wrote:
    My goal is to break apart an
    entirely LabView created application so I can still use parts of it
    (builded as Shared DLLs upon on some VIs) in my new .Net application.
    My problem is that some others VIs (that I am not intending using) are
    changing those global variables (in the natural data flow of the
    application).  I could , of course, send the values of those
    global variables as parameters, but I don't know how should I pass
    those data types (and their size)... There are some clusters there...
    Any help is well appreciated
    Your
    problem is of course the use of globals. That is almost always a bad
    idea and asking for troubles once your application gets bigger.
    Avoiding race conditions and undesired influences between different
    parts of your application will take up more and more of your
    development time as your project grows.
    You should look into Functional Globals (LV2 style globals) and shift
    registers for data storage and queues for passing information between
    different parts of your applciation. Using these techniques
    consequently, will require you to spend some more time initially but
    will allow you to grow your application without increasing the
    complexity of managing such things exponentially.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • How can I pass Global Variable from Page1 to Page2

    I have the following senario.
    Pag1 - report is based on following PL\SQL
    declare
    g1 varchar2(100);
    begin
    g1 = select * from emp where dept = 10;
    return g1;
    end;
    Now I have Page2 - based on following PL\SQL
    declare
    g2 varchar2(100);
    begin
    g2 := g1; -- here i want to use variable g1???
    return g2;
    end;
    My question is - How can I use variable g1 from P1 in my new page P2.
    Thanks,
    Deepak

    Hi Andy,
    Thanks for the clarification.
    I did exactly the same, created a new Region with HTML (PL\SQL) and got the output. it was fine.
    Now when I am using exactly the same code in a Report (PL/SQL function returning a SQL Query), I am getting the following error.
    DECLARE
    g VARCHAR2(100);
    BEGIN
    g := 'This is a test string';
    APEX_UTIL.SET_SESSION_STATE('G_SQL_STRING', g);
    htp.p(v('G_SQL_STRING'));
    END;
    ERR-1002 Unable to find item ID for item "FLOW_SECURITY_GROUP_ID" in application "4000".
    ERR-1002 Unable to find item ID for item "G_SQL_STRING" in application "4000".
    I am doing the same thing, nothing changed....only difference is in 1st case I am using HTML (PL\SQL) Region and in 2nd case using the REPORT Region (PL/SQL function returning a SQL Query)
    thanks,
    deepak

  • [Bash] How to `declare` a global variable inside a function?

    #!/bin/bash
    # Not using declare -A, array will be treated as indexed array rather than an associative array
    seta()
    for ((n=0;n<$1;n++)); do
    printf -v a_$n[k] %s k$n
    printf -v a_$n[j] %s j$n
    eval echo inside seta: a_$n[k] = \$\{a_$n\[k\]\}
    done
    seta 3
    echo outside: a_0[k] = ${a_0[k]}
    echo outside: a_0[j] = ${a_0[j]}
    echo
    # Use declare -A inside function, array will be undefined outside
    setb()
    for ((n=0;n<$1;n++)); do
    declare -A b_$n # Note here
    printf -v b_$n[k] %s k$n
    printf -v b_$n[j] %s j$n
    eval echo inside setb: b_$n[k] = \$\{b_$n\[k\]\}
    done
    setb 3
    echo outside: b_0[k] = ${b_0[k]}
    echo outside: b_0[j] = ${b_0[j]}
    echo
    # The bad solution, only works if we know beforehand how many c_? arrays will be assigned inside setc()
    for ((n=0;n<3;n++)); do
    declare -A c_$n
    done
    setc()
    for ((n=0;n<$1;n++)); do
    printf -v c_$n[k] %s k$n
    printf -v c_$n[j] %s j$n
    eval echo inside setc: c_$n[k] = \$\{c_$n\[k\]\}
    done
    setc 3
    echo outside: c_0[k] = ${c_0[k]}
    echo outside: c_0[j] = ${c_0[j]}
    My original code does the declare -A as in setb(). I was surprised when I saw all blank output... Now the problem is illustrated clearly by the setb() example.
    The setc() example works, but a bit ugly: look at the two 3's...
    My ideal solution would be, something like `declare_global -A b_$n` in setb()
    Any ideas?

    with current bash versions, i don't think it is possible to declare global associative arrays in functions.
    what you are after is the "-g" option of typeset which is available in zsh.
    i think i read somewhere that something similar may be planned for bash 4.2.

  • How to use a global variable for reading a query resultset in JDBC lookup?

    Hi Friends,
    Using JDBC lookup, I am trying to read from a table Emp1 using a user defined function. In PI 7.0, this function returns values of a single column only even if you fire a " Select * " query. I am planning to use a global variable(array) that stores individual column values of the records returned by a "select *" query. Need pointers on as to how a global variable can be declared and used to acheive the above scenario. Kindly explain with an example. Any help would be appreciated.
    Thanks,
    Amit.

    Hi Amit,
    Sounds like a good idea but then you would need an external db and update the table in a thread safe way !.
    Regarding your question as to how to work with global variable please refer https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/1352. [original link is broken] [original link is broken] [original link is broken]
    Rgds
    joel

  • How can I access global variables in a loaded Applescript?

    How can I access global variables in a loaded script, in Xcode, ApplescriptObjC? Basically, I have a global variable defined in my parent script using "property", and I need to modify objects connected to those variables inside of a loaded script.
    Example:
    Parent script:
    script AppDelegate
    property myTextField : missing value
    //linked to a text field object
    tell myScript to myAwesomeHandler_()
    end script
    Loaded script:
    on myAwesomeHandler_()
    myTextField's setStringValue_("The new Xcode is so glitchy ugh")
    //changes value of linked text field of parent script
    end myAwesomeHandler_
    The problem is, the variable is undefined in the Loaded script, and I need it to have the same value as the parent script, and I don't want to pass the variable through the Handler. Any ideas?

    I think want you are looking to do will need to be done in two steps. Because myTextField needs to be a property for the ObjectiveC part of the code you cannot turn it into a global.
    However if you make a temporary variable global assign the string to it in the handler then set myTextField off of it.
    global myTextFieldGlobal
    script AppDelegate 
    property myTextField : missing value 
    //linked to a text field object 
    tell myScript to myAwesomeHandler_() 
    myTextField's setStringValue_(myTextFieldGlobal)
    end script 
    on myAwesomeHandler_() 
    set myTextFieldGlobal to "The new Xcode is so glitchy ugh"
    //changes value of linked text field of parent script 
    end myAwesomeHandler_ 
    I know you stated you did not want the handler to return a value but I have to ask why? Global's, imo, are not a good idea and really should be used as a last resort.
    One other possibility is to pass a reference to the property to the handler. Not sure if that works in AS of if that would satisfy our requirement of not passing the variable through the handler
    <edit>
    Another though have you tried to define the property outside the script?  That is
    property myTextField : missing value
    script AppDelegate
    Not sure if that will work.
    You might also want to have a look at Scope of Properties and Variables Declared in a Script Object

  • How can I define global variable in user exit whic I can use anywhere.

    Hi all,
    How can I define global variable( Table ) which I can use when it come back to same user exit where I defined and stored some data.
    What I mean is I want to define 1 global table.
    In user exit when it comes I store some information. and again when it will come I will have that stored information so I can use it.
    Thanks a lot in advance.

    You can use EXPORT  TO MEMORY ID and IMPORT FROM MEMORY ID Statement for this.
    EXPORT T_ITAB FROM T_ITAB TO MEMORY ID 'ABC'.
    IMPORT T_ITAB TO T_ITAB FROM MEMORY ID 'ABC.'

  • How to create a global variable in forms 6i

    How to create a global variable in forms 6i

    :GLOBAL.my_var := 15; Well, this statement is not correct! Global variables
    stores a character string of up to 255 characters in
    length. Thus, valid statement for Khurram example
    is:
    :GLOBAL.my_var := TO_CHAR(15);
    or
    :GLOBAL.my_var := '15';
    But numeric values are implicitly converted by oracle so there's nothing in fact wrong with the statement...
    :GLOBAL.my_var := 15;
    ;)

  • How can I access JSP variables from a JavaScript function in a JSP page?

    Respected sir
    How can I access JSP variables from a JavaScript function in a JSP page?
    Thanx

    You may be get some help from the code below.
    <%
        String str="str";
    %>
    <script>
        function accessVar(){
           var varStr='<%=str%>';
           alert(varStr);// here will diplay 'str'
    </script>

  • How to declare a bind variable with 'date' data type in command prompt?

    how to declare a bind variable with 'date' data type in command prompt?
    sql>variable q date;
    when i execute it show list of datatypes

    Hi,
    As Lokanath said, there are no DATE bind variables.
    You can use a VARCHAR2 bind variable, and convert it to a DATE in your SQL statment.
    If you're using SQL*Plus, consider a substitution variable. It won't be as efficient as a bind variable, but it will be as convenient.
    For example:
    DEFINE  first_entrry_date = "DATE '2010-06-20''
    SELECT   ...
    WHERE   entry_date >= &first_entry_date
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to get an environment variable from OS in class ?

    Hello,
    How to get an environment variable from OS in class ?
    Thanks !

    An example of a Java application that does this is Ant, when you add a line like this in your build.xml:
    <!-- Import environment variables -->
    <property environment="env"/>
    I have looked at the source code of Ant 1.3, especially the file src/main/org/apache/tools/ant/taskdefs/Execute.java. Look at the methods getProcEnvironment() and getProcEnvCommand(). Ant uses an OS-dependent trick to get the environment variables.
    You can download the Ant source code from http://jakarta.apache.org/ant
    Jesper

  • Tell me how to format a date retrieved from a MS SQL Server 2000 database?

    Tell me how to format a date retrieved from an MS SQL Server 2000 database for various uses in my JSP page?

    Or if you want to use JSTL instead of a scriptlet see:
    http://forum.java.sun.com/thread.jspa?threadID=676754&tstart=0

  • How to get second maximum salary from employee table(sql query)

    how to get second maximum salary from employee table(sql query)

    dude there is no matter of structure .........that user already said its from employee table ...............its basic table in sql and there is no need to specify the table structure
    .........i think u got my point I think you are the one who didn't understand Sarma's point.
    Give a man a fish and you feed him once. Teach a man how to fish and you feed him a life long.
    >
    and the query is
    select max(sal) from emp where sal<(select max(sal)
    from emp);
    this will give the 2nd max salary from the emp tableBtw: You solution is bad, because it needs to scan and sort the table emp twice. And a better solution has been given already.
    Message was edited by:
    Sven W. - reordered statements

  • The -dataSource parameter in assemble a web service from a PL/SQL package

    When I use Web Service Assembler to assemble a Web Service from a PL/SQL package, I need to specify the dataSource parameter, e.g.:
    java -jar wsa.jar -plsqlAssemble -sql pkgname -dataSource jdbc/MyDS -dbConnection ... -dbUser scott/tiger ....
    The dataSource also needs to be pre-configured in the data-sources.xml in OC4J.
    I am wondering why dataSource is needed here because the database connection information is already specified on the commandline ( dbConnection and dbUser).
    If I have to specify dataSource, how do I configure data-sources.xml dynamically at run-time (e.g., adding entries)?
    Thanks,
    Jim

    The -dataSource parameter specifies the data-sources.xml entry used at runtime. The database connection info is only for design time use. Typically you make sure data-sources.xml contains an entry with jndi-location of the same name you specifies for -dataSource. To configure data-sources.xml at runtime, it is out of the scope of web services. Please refer to OC4J admin guide. You can probably modify the data-sources.xml file and force OC4J to reconfigure based on the new data-sources.xml file.

  • How to declare a global/public variable in Oracle Forms

    Hi All,
    I have to get the value of a variable which is declared in the event 'When_Button_Pressed', in an another trigger with in the form.
    My variable & type
    l_db_handle EXEC_SQL.ConnType;
    This variable used to get the handle of a new database connection.
    (Here I am trying to make connection to two different databases from Form. That is working fine.)
    I have tried with Global variable to transfer this variable value to other triggers. But it is not working. It shows 'Wrong type error'
    Could you please let me know, how can I declare which DB handle variable as public in form(I mean i have to use this variable all the triggers with in the form)
    Thanking You,
    Manu

    Put the code in a package within the form, have the triggers call functions/procedures within the package. All variables which need to be referenced in more than one procedure can be created as package variables.

Maybe you are looking for

  • VBA code to update Excel Data in sharePoint list

    hi Team, I have excel sheet created having data. I need to upload it in sharepoint List. Please provide me VBA code for the same.

  • Does an upgrade cure an update disaster?

    I have an iMac my family uses running Snow Leopard and during the automatic Software Update installation of the 10.6.8 Update last year the Mac hung: 10.6.8 update crashed before it completed and now the Finder won't launch. Fortunately for me, I had

  • "Could Not Open the Communication Device"  ???

    I use a dial up connection. Everytime I try to connect to the internet, after it dials a message box pops up that says "Could Not Open the Communication Device". Has anyone else had this problem? And how do I fix it? Please help me.

  • Consuming Web Service from ABAP: ERROR_WEBSERVICE_RUNTIME_INIT

    Hi fellows, I have to make a call from SAP (CRM) to external system (via webservice) for this purpose I've setup a new Proxy-Object, uploaded the WSDL file (locally) and Created a Logical port. In the Logical Port under the tab Call Parameter I've de

  • Cannot sync music purchased on AppleTV to iTunes with 2.0.2

    Prior to 2.0.2, music purchased through AppleTV would sync just fine with iTunes (Windows XP). Now, music purchased through AppleTV after I updated to 2.0.2 does not sync with iTunes, nor does it show up in the "Purchased on AppleTV" list in iTunes.