Variable scope in package

I have some procedures in a package that need almost the same type of variables. Now, lets say I put them in the package spec in the private variable declaration part so that all the procedures use the same variables instead of declaring them inside all procedures. Now, if someone is executing those procs simultaneously will Oracle Oracle create a separate instance of those variables or use the same copy of the variables for all the simultaneously executing procedures?
Also, is it a good practise to put these variables in the package body section so that they become public?

another question!
is it advisable to put some kind of driver proc in the package such that its job is just to invoke other procs of the package when called like:
create or replace package body mypack is
procedure proc proc_main(params) is
begin
proc1(params); --invoke other procs
proc2(params);
procn(params);
end ;--end of proc
--package initialization section
begin
proc_main(params);
end; --end of package                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Variable Scope at package or interface level

    Hi,
    Can we set the ODI Project variable scope to package or interface level
    because in my project im using a last rundate refresh variable this variable value will be changed at the time of execution of each package.
    Thanxs
    Madhavi

    you can create it as "Not Persistent" and then its value exist per ODI session.
    In this way, several sessions can keep independent value to the same variable.

  • Variable refreshing in package header

    Hello Experts,
    Through a function in my package header I fill up a global variable. The function gets the value out of a table in my database:
    PV_FILENAME PARAMETERS.VALUE%TYPE DL$PARAMETERS.VALUE_BY_NAME('FILE_NAME'); This works fine, however when I change the value in the table and commit the changes the problem begins.
    When I execute the following statement to check if the value changed:
    select DL$PARAMETERS.VALUE_BY_NAME('FILE_NAME') from dual;It shows me the new value...
    But the variable in the package still contains the old value. When I restart sql developer the variable adjusts.
    Does anyone know what I can do? It seems like the package is caching the value or something. Or is it obligatory to put global variables in the body?
    greets
    Edited by: iadgroe on May 21, 2012 6:37 AM

    Hello Arun,
    I can check this because the return value I use in the function is the name of an xml file (e.g. 'xmlfile_1.xml'):
    SELECT .....
    FROM XMLTABLE('/employees/employee' PASSING XMLTYPE(BFILENAME(PV_DIRECTORY, -->PV_FILENAME<--), NLS_CHARSET_ID('AL32UTF16'))
    COLUMNS USERNAME VARCHAR2(20) PATH './name/userName' , TIMEREG XMLTYPE PATH './timeRegistration/days' ) H,
        XMLTABLE('days/day' PASSING H.TIMEREG COLUMNS TIMESHEET_DATUM In the above code I use the name to retrieve the xml file. I insert the data in the xml file into one of my own tables.
    When I change the value of the xml-name(e.g. 'xmlfile_2.xml') in my table that the function returns, the variable should reference another xml-file. However when I execute the procedure in my package it still insert data from the previous xml(xmlfile_1.xml) file into my table.
    I this clear enough? :-)
    Thanks a lot!

  • Best way to deal with hard coded variables in a package

    There is a plsql package that reads a line from a file, parses the data, does a ton of sql operation with it (select update, inserts, calculations) and then writes the output to an output file.
    The file names and the firectories are retieved from a database table.
    Example:
    select location,file_name into loc_in,file_in from temp_tbl;
    p_File_handle := utl_file.fopen (loc_in, file_in, 'W');
    My co worker is suggesting that getting the variable values from the table is not a good practice. He suggests that the values should be hard-coded in the program. Now you might ask what would happen if the file name or directory changes. His suggestion is to have a build file and do a token substitution of those hard coded values in the program and then load in to the DB. In short the process will involve the following steps:
    -Get the package from the repostory.
    -Change the file name and directory in the token file.
    -Run the build process that will replace the values in the package .
    -Load the new file (with the updated values) in to the DB.
    Example:
    This way the program will be initially coded like this:
    p_File_handle := utl_file.fopen ('${loc_in}', '${file_in}', 'W');
    After the build file runs, it will replace the values as
    p_File_handle := utl_file.fopen ('C:/test', 'testfile.dat', 'W');
    Once the file has changed with the new updated values, compile that into the database.
    Ideas/comments?

    Re: Best way to deal with hard coded variables in a package: why have you reposted using a new profile?
    Neither post provides enough clear information on what the actual requirement is. We need more data in order to comment on your idea, your co-worker's, or to suggest alternatives.
    My co worker is suggesting that getting the variable
    values from the table is not a good practice.His reasons for this are...?
    "variable values": Why do they vary? How often do they change?
    The file names and the directories are retrieved from
    a database table.How do the values get into the table? What is the volume of the data?
    Oracle version? Operating system?

  • Bind variable inside a package

    Can we declare a bind variable inside a package specification?
    CREATE OR REPLACE PACKAGE GET_EMPLOYEEDETAILS
    IS
    PROCEDURE GET_FIRSTNAME(E_ID IN EMPLOYEES.EMPLOYEE_ID%TYPE, F_NAME OUT EMPLOYEES.FIRST_NAME%TYPE);
    VARIABLE O VARCHAR2(20);
    END GET_EMPLOYEEDETAILS ;
    CREATE OR REPLACE PACKAGE BODY GET_EMPLOYEEDETAILS
    IS
    PROCEDURE GET_FIRSTNAME(E_ID IN EMPLOYEES.EMPLOYEE_ID%TYPE, F_NAME OUT EMPLOYEES.FIRST_NAME%TYPE)
    IS
    BEGIN
    SELECT FIRST_NAME INTO F_NAME FROM EMPLOYEES WHERE EMPLOYEE_ID = E_ID;
    DBMS_OUTPUT.PUT_LINE(F_NAME);
    END;
    END GET_EMPLOYEEDETAILS;
    Output:
    ERROR at line 4: PLS-00103: Encountered the symbol "VARCHAR2" when expecting one of the following:
      := . ( @ % ; not null range default character
    The symbol ":=" was substituted for "VARCHAR2" to continue.
    2. IS
    3. PROCEDURE GET_FIRSTNAME(E_ID IN EMPLOYEES.EMPLOYEE_ID%TYPE, F_NAME OUT EMPLOYEES.FIRST_NAME%TYPE);
    4. VARIABLE O VARCHAR2(20);
    5. END GET_EMPLOYEEDETAILS ;
    6. /
    or is there any alternative for bind variables inside an package
    Thanks in advance
    Message was edited by: 1009739

    The "VARIABLE O VARCHAR2(20);" syntax is the way SQLPlus declared bind variables - it is specific to the client. Because PL/SQL packages and procedures are server code that continue past sessions, its only access to the client environment is what the client gives it - it can't go and create a bind variable in the client.
    PL/SQL procedures, functions and packages run from lots of environments, so they cannot access bind variables inside their body - you have to pass any external variables as parameters.
    Anonymous PL/SQL blocks can access bind variables.
    You can declare package public global variables - just leave out that "VARIABLE". E.g.
    CREATE OR REPLACE PACKAGE GET_EMPLOYEEDETAILS
    IS
    PROCEDURE GET_FIRSTNAME(E_ID IN EMP.EMPNO%TYPE, F_NAME OUT EMP.ENAME%TYPE);
    O VARCHAR2(20);
    END GET_EMPLOYEEDETAILS ;
    For local variables in your procedure, just put them between the IS and BEGIN. Using them in SQL inside the PL/SQL automatically uses them as a bind variable.
    create or replace PROCEDURE GET_FIRSTNAME(E_ID IN EMP.EMPNO%TYPE, F_NAME OUT EMP.ENAME%TYPE)
    IS
      O VARCHAR2(20);
      O2 VARCHAR2(21);
    BEGIN
      O := 'FR%';
    SELECT ENAME INTO F_NAME FROM EMP WHERE EMPNO = E_ID and ENAME like O;
    O2 := F_NAME || '2';
    DBMS_OUTPUT.PUT_LINE(F_NAME);
    END;
    O is bound in the query.
    To access bind variables from anonymous PL/SQL, first declare them in the calling environment. In SQL Plus that's
    VARIABLE O VARCHAR2(20);
    In Pro*C it's
    EXEC SQL BEGIN DECLARE SECTION;
      char[21] O
    EXEC SQL END DECLARE SECTION;
    Then reference it in anonymous PL/SQL with a colon as prefix:
    BEGIN
    SELECT FIRST_NAME INTO :O FROM EMPLOYEES WHERE EMPLOYEE_ID = E_ID;
    END;
    This only works for anonymous blocks (starting with BEGIN or DECLARE). As I said, PL/SQL procedures, functions and packages cannot see bind variables from the calling environment

  • What target property must be specified while passing a object type variable to child package in SSIS 2012

    What target property must be specified while passing a object type variable to child package in SSIS 2012???

    As shown below, there is variable strVar and it's Value property is selected. Likewise you have to select the property that you need to pass.
    Please refer:
    http://www.bidn.com/blogs/MikeDavis/ssis/155/passing-variable-values-from-parent-package-to-child-ssis
    -Vaibhav Chaudhari

  • Javascript discussion: Variable scopes and functions

    Hi,
    I'm wondering how people proceed regarding variable scope, and calling
    functions and things. For instance, it's finally sunk in that almost
    always a variable should be declared with var to keep it local.
    But along similar lines, how should one deal with functions? That is,
    should every function be completely self contained -- i.e. must any
    variables outside the scope of the function be passed to the function,
    and the function may not alter any variables but those that are local to
    it? Or is that not necessary to be so strict?
    Functions also seem to be limited in that they can only return a single
    variable. But what if I want to create a function that alters a bunch of
    variables?
    So I guess that's two questions:
    (1) Should all functions be self-contained?
    (2) What if the function needs to return a whole bunch of variables?
    Thanks,
    Ariel

    Ariel:
    (Incidentally, I couldn't find any way of  marking answers correct when I visited the web forums a few days ago, so I gave up.)
    It's there...as long as you're logged in at least, and are the poster of the thread.
    What I want is to write code that I can easily come back to a few months later
    and make changes/add features -- so it's only me that sees the code, but
    after long intervals it can almost be as though someone else has written
    it! So I was wondering if I would be doing myself a favour by being more
    strict about make functions independent etc. Also, I was noticing that
    in the sample scripts that accompany InDesign (written by Olav Kvern?)
    the functions seem always to require all variables to be passed to it.
    Where it is not impractical to do so, you should make functions independent and reusable. But there are plenty of cases where it is impractical, or at least very annoying to do so.
    The sample scripts for InDesign are written to be in parallel between three different languages, and have a certain lowest-common-denominator effect. They also make use of some practices I would consider Not Very Good. I would not recommend them as an example for how to learn to write a large Javascript project.
    I'm not 100% sure what you mean by persistent session. Most of my
    scripts are run once and then quit. However, some do create a modeless
    dialog (ie where you can interface with the UI while running it), which
    is the only time I need to use #targetengine.
    Any script that specifies a #targetengine other than "main" is in a persistent session. It means that variables (and functions) will persist from script invokation to invokation. If you have two scripts that run in #targetengine session, for instance, because of their user interfaces, they can have conficting global variables. (Some people will suggest you should give each script its own #targetengine. I am not convinced this is a good idea, but my reasons against it are mostly speculation about performance and memory issues, which are things I will later tell you to not worry about.)
    But I think you've answered one of my questions when you say that the
    thing to avoid is the "v1" scope. Although I don't really see what the
    problem is in the context of InDesign scripting (unless someone else is
    going to using your script as function in one of theirs). Probably in
    Web design it's more of an issue, because a web page could be running
    several scripts at the same time?
    It's more of an issue in web browsers, certainly (which I have ~no experience writing complex Javascript for, by the way), but it matters in ID, too. See above. It also complicates code reuse across projects.
    Regarding functions altering variables: for example, I have a catalog
    script. myMasterPage is a variable that keeps track of which masterpage
    is being used. A function addPage() will add a page, but will need to
    update myMasterPage because many other functions in the script refer to
    that. However, addPage() also needs to update the total page count
    variable, the database-line-number-index-variable and several others,
    which are all used in most other functions. It seems laborious and
    unnecessary to pass them all to each function, then have the function
    alter them and return an array that would then need to be deciphered and
    applied back to the main variables. So in such a case I let the function
    alter these "global" (though not v1) variables. You're saying that's okay.
    Yes, that is OK. It's not a good idea to call that scope "global," though, since you'll promote confusion. You could call it...outer function scope, maybe? Not sure; that assumes addPage() is nested within some other function whose scope is containing myMasterPage.
    It is definitely true that you should not individually pass them to the function and return them as an array and reassign them to the outer function's variables.
    I think it is OK for addPage() to change them, yes.
    Another approach would be something like:
    (function() {
      var MPstate = {
        totalPages: 0,
        dbline: -1
      function addPage(state) {
        state.totalPages++;
        state.dbline=0;
        return state;
      MPstate = addPage(MPstate);
    I don't think this is a particularly good approach, though. It is clunky and also doesn't permit an easy way for addPage() to return success or failure.
    Of course it could instead do something like:
        return { success: true, state: state };
      var returnVal = addPage(MPstate);
      if (returnVal.success) { MPstate = returnVal.state; }
    but that's not very comforting either. Letting addPage() access it's parent functions variables works much much better, as you surmised.
    However, the down-side is that intuitively I feel this makes the script
    more "messy" -- less legible and professional. (On the other hand, I
    recall reading that passing a lot of variables to functions comes with a
    performance penalty.)
    I think that as long as you sufficiently clearly comment your code it is fine.
    Remember this sort of thing is part-and-parcel for a language that has classes and method functions inside those classes (e.g. Java, Python, ActionScript3, C++, etc.). It's totally reasonable for a class to define a bunch of variables that are scoped to that class and then implement a bunch of methods to modify those class variables. You should not sweat it.
    Passing lots of variables to functions does not incur any meaningful performance penalty at the level you should be worrying about. Premature optimization is almost always a bad idea. On the other hand, you should avoid doing so for a different reason -- it is hard to read and confusing to remember when the number of arguments to something is more than three or so. For instance, compare:
    addPage("iv", 3, "The rain in spain", 4, loremIpsumText);
    addPage({ name: "iv", insertAfter: 3, headingText: "The rain in spain",
      numberColumns: 4, bodyText: loremIpsumText});
    The latter is more verbose, but immensely more readable. And the order of parameters no longer matters.
    You should, in general, use Objects in this way when the number of parameters exceeds about three.
    I knew a function could return an array. I'll have to read up on it
    returing an object. (I mean, I guess I intuitively knew that too -- I'm
    sure I've had functions return textFrames or what-have-you),
    Remember that in Javascript, when we say Object we mean something like an associative array or dictionary in other languages. An arbitrary set of name/value pairs. This is confusing because it also means other kinds of objects, like DOM objects (textFrames, etc.), which are technically Javascript Objects too, because everything inherits from Object.prototype. But...that's not what I mean.
    So yes, read up on Objects. They are incredibly handy.

  • Undefined variable, class, or package name

    The following code in the jsp is supposed to display the correct 'Securities' link based on the app_main_frames URL. I am getting an error. Can anyone help?
    <% if (parent.app_main_frame.location == ("http://ccmsun57.ccminvest.com:8080/cgi-java/Allocation/jsp/scenario.jsp?source=init")) { %>
    Securities
    <% } else { %>
    <a href="/cgi-java/Holdings/jsp/SecurityInventoryQuery.jsp?which_search=none&which_category=none
    target="app_main_frame">Securities</a>
    <% } %>
    I am getting the following error:
    Generated servlet error:
    /opt/JBoss-2.4.4_Tomcat-4.0.1/catalina/work/localhost/cgi-java/common/jsp/NavigationMenu$jsp.java:173:
    Undefined variable, class, or package name: parent
    if (parent.app_main_frame.location ==
    ^
    ("http://ccmsun57.ccminvest.com:8080/cgi-java/Allocation/jsp/scenario.jsp?source=init")) {

    If app_main_frame is a frame in a frameset then you cannot
    simply refer to it in a Java scriptlet.
    You can refer to it in a JavaScript script, like this:
    <script>
    if (parent.app_main_frame.location == "http://ccmsun57.ccminvest.com:8080/cgi-java/Allocation/jsp/scenario.jsp?source=init")
       document.write("<a href=\"javascript:submit_Form('none')\"target=\"app_main_frame\">Securities</a>");
    else
       document.write("<a href=\"/cgi-java/Holdings/jsp/SecurityInventoryQuery.jsp?which_search=none&which_category=none\"target=\"app_main_frame">Securities</a>");
    </script>

  • Cfm template updating cfc variable scope

    Don't know if anybody's run into this before, but I ran into a strange issue with the variable scope in a cfc.  Basically, I have some application settings stored in a database table, and then I have a cfc saved to application scope in which I store the contents of the table in a variable scope query.  Within the cfc, I have a getter function that preforms a query of queries to pull the data I need.  I then have an admin screen within the application to update the settings.
    This is (very generally) what my cfc looks like:
    <cfcomponent  name="settings.cfc">
         <cffunction name="init" returntype="settings">  
              <cfset setAppSettings() />  
              <cfreturn this />  
         </cffunction>  
         <cffunction name="setAppSettings">  
              <cfquery name="variables.qrySettings" datasource="#application.dsn#">  
                   SELECT *
                   FROM SETTINGS
              </cfquery>  
         </cffunction>  
         <cffunction name="getAppSettings" returntype="query">  
              <cfargument name="id" />
              <cfset var local = structNew() />  
              <cfquery name="local.qryResult" dbtype="query">  
                   SELECT *
                   FROM variables.qrySettings
                   WHERE ID = <cfqueryparam value="#arguments.id#" cfsqltype="cf_sql_numeric" />  
              </cfquery>  
              <cfreturn local.qryResult />  
         </cffunction>  
    </cfcomponent>
    In onApplicationStart in Application.cfc, I have this line:
    <cfset  
    application.objSettings = createObject("component","settings").init() />

    Sorry, accidentally posted before I was done...
    Basically, the problem is that I have an admin screen that updates the settings.  I call the getter function in a cfm template, and I save the result to a variable called variables.qrySettings (same name as in the cfc) like this - <cfset variables.qrySettings = application.objSettings.getAppSettings(url.id) />.  For some reason, this seems to overwrite variables.qrySettings in the cfc.  Any ideas????

  • Variable scope in plsql package

    When I run the following package, proc2 is always printing the value of i = 1 even though proc1 is incrementing the value of i correctly? Could any one explain to me what is the problem with this code?
    CREATE OR REPLACE PACKAGE test_pkg
    is
    PROCEDURE proc1 (p_fetch_limit in number := 200);
    PROCEDURE proc2 (rec_id out number);
    END test_pkg;
    CREATE OR REPLACE PACKAGE BODY test_pkg
    IS
    cursor test_cur
    IS
    select new_app,
    card_number,
    process_flag,
    process_date,
    seq_number
    from wm_opt_scan_temp
    where process_flag = 'N' and process_date IS null
    and new_app = 'Y'
    order by seq_number;
    type test_cur_type IS table of test_cur%rowtype;
    cur_rec test_cur_type;
    i number := 1;
    l_rec_id number := 0;
    -- PROC1 --
    PROCEDURE proc1 (p_fetch_limit in number := 200)
    IS
    BEGIN
    open test_cur;
    loop
    fetch test_cur bulk collect into cur_rec limit p_fetch_limit;
    exit WHEN cur_rec.count = 0;
    for i in 1..cur_rec.count
    loop
    DBMS_OUTPUT.put_line('proc1 - i<'||i||'> seq#<'||cur_rec(i).seq_number||'> card#<'||cur_rec(i).card_number||'>');
    l_rec_id := 0;
    proc2(l_rec_id);
    END loop;
    END loop;
    CLOSE test_cur;
    COMMIT;
    DBMS_OUTPUT.put_line('proc1 procedure finished...');
    END proc1;
    -- PROC2 --
    PROCEDURE proc2 (rec_id out number)
    IS
    BEGIN
    DBMS_OUTPUT.put_line('proc2 started - i<'||i||'> seq#<'||cur_rec(i).seq_number||'> card#<'||cur_rec(i).card_number||'>');
    END proc2;
    END test_pkg;
    output is:
    Connecting to the database Test.
    proc1 - i<1> seq#<7841> card#<40992814376>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<2> seq#<8041> card#<40992779256>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<3> seq#<8241> card#<40992745696>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<4> seq#<12681> card#<40992814376>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<5> seq#<12682> card#<40992814375>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<6> seq#<12683> card#<40992814378>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<7> seq#<12684> card#<40992814379>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<8> seq#<12685> card#<40992745756>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<9> seq#<12686> card#<40992745757>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<10> seq#<12689> card#<40992814377>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<11> seq#<12690> card#<40992745755>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<12> seq#<12691> card#<40992745767>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<13> seq#<12692> card#<40992745771>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<14> seq#<12693> card#<40992745612>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<15> seq#<12694> card#<40992145673>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<16> seq#<12695> card#<40992745611>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<17> seq#<12697> card#<40992745661>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<18> seq#<12698> card#<40992745689>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<19> seq#<12700> card#<40992745771>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 procedure finished...
    Process exited.
    Disconnecting from the database Test.

    Assign it to a separate global variable, and don't name it "i" so that the global variable is visible within the for loop.
    As for Java, consider the following:
    public class Foo {
    private int i;
    public void proc1() {
    for (int i=0;i<10;i++) {
    // do stuff
    public void proc2() {
    System.out.println("i = "+i);
    Same problem: two variables in different scopes, both named "i".

  • Scope of globle and locale variable of a Package

    I have query about scope of variable declared in spec and body of a package. like
    create or replace package pk_test as
    v_var varchar2(50);
    procedure pk_p_test;
    end ;
    create or replace package body pk_test as
    v_var varchar2(50) := 'aaa';
    procedure pk_p_test
    is
    --v_var varchar2(50) := 'bbbb' ;
    begin
    null;
    --dbms_output.put_line(pk_p_test.v_var);
    dbms_output.put_line(pk_test.v_var);
    dbms_output.put_line(*v_var*);
    end;
    end;
    declare
    begin
    pk_test.v_var := 'qqqqq';
    --dbms_output.put_line(pk_test.v_var);
    pk_test.pk_p_test() ;
    end ;
    package is allowing to declare variable having same name in spec and body.
    But its not allowing to access. is it bug or .. can we access that variable using some methods

    Ah, I think I can see what you are saying.
    Yes, it can be declared in either place, or even declared in both places, but it shouldn't be declared in both.
    One is a "public" state variable and the other is a "private" state variable, so when it creates the package state, they are both marked differently within the state and therefore unique, hence it compiles.
    The public one can be accessed from outside the package, because it's clear to Oracle which is being referred to...
    SQL> create or replace package pk_test as
      2  v_var varchar2(50);
      3  procedure pk_p_test;
      4  end ;
      5  /
    Package created.
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace package body pk_test as
      2    v_var varchar2(50) := 'aaa';
      3    procedure pk_p_test is
      4    begin
      5      null;
      6    end;
      7* end;
    SQL> /
    Package body created.
    SQL> exec pk_test.v_var := 'aaa';
    PL/SQL procedure successfully completed.
    SQL> set serverout on
    SQL> exec dbms_output.put_line(pk_test.v_var);
    aaa
    PL/SQL procedure successfully completed.However if you try and access the variable from inside the package, the body is able to reference both the public and private variables, so it doesn't know which one to use. Hence the compilation error previously seen.
    It's not a bug, because the packages are being flexible to allow for public and private variables, but what you are experiencing just indicates poor package design and lack of understanding of package state variables.

  • Same variable declaration in package

    Hi
    Please go through below lines of code where I have declared same variable 2 times, which got compiled successfully. But If I do the same in stand alone procedure it throws an error. In case of creation of package it says package created. Can anyone justify to this .....
    SQL> create or replace package
    2 may221
    3 as
    4 a number := 10 ;
    5 a number := 20 ;
    6 procedure p1(a number) ;
    7 end ;
    8 /
    Package created.
    SQL> create or replace package body may221
    2 as
    3 procedure p1(a number)
    4 as
    5 begin
    6 dbms_output.put_line(a) ;
    7 end ;
    8 end ;
    9 /
    Package body created.
    SQL> set serverout on
    SQL> exec may221.p1(20);
    20
    PL/SQL procedure successfully completed.
    SQL> begin
    2 dbms_output.put_line(may221.a) ;
    3 end ;
    4 /
    dbms_output.put_line(may221.a) ;
    ERROR at line 2:
    ORA-06550: line 2, column 32:
    PLS-00371: at most one declaration for 'MAY221.A' is permitted in the declaration section
    ORA-06550: line 2, column 4:
    PL/SQL: Statement ignored
    Thanks and Regards
    JC

    > I checked it's working fine.. no errors..
    Oracle version?
    There is an error as there are two definitions of variable a. This will generate a run-time error when that variable is used.
    However, the result of procedure P1 is not an error.
    It is all a matter of scope. Scope determines the resolution of a reference (like a variable name, object name, column name, table name, etc.)
    The scope is first local - which means the local code block is checked for resolution. And the variable a is found. In o-o terms, when you refer to variable a it is first resolved as self.a - and only when that fails, the scope changes to the "encapsulating" unit which is the package.
    The following code illustrates:
    SQL> create or replace package FooPackage is
    2 a number := 10;
    3 a number := 11;
    4
    5 procedure Show( a number );
    6 end;
    7 /
    Package created.
    SQL> show errors
    No errors.
    SQL>
    SQL>
    SQL> create or replace package body FooPackage is
    2 procedure Show( a number ) is
    3 begin
    4 DBMS_OUTPUT.put_line( a ); -- <= resolved as self.a
    5 end;
    6 end;
    7 /
    Package body created.
    SQL> show errors
    No errors.
    SQL>
    SQL>
    SQL> exec FooPackage.Show( 12 )
    12
    PL/SQL procedure successfully completed.
    SQL> exec DBMS_OUTPUT.put_line( FooPackage.a );
    BEGIN DBMS_OUTPUT.put_line( FooPackage.a ); END;
    ERROR at line 1:
    ORA-06550: line 1, column 40:
    PLS-00371: at most one declaration for 'FOOPACKAGE.A' is permitted
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored

  • Simple question Of variable scope

    If u do not define any scope for a variable waht is the default scope for the variable.
    is it private Public or some thing in between the two ????

    The default access has no keyword, but it is commonly referred to as "friendly"
    It means that all the other classes in the current package have access to the friendly member, but to all the classes outside of this package the member appears to be private.

  • How can I use variable for a package filename and target file inODIFileMove

    I want to use a variable for paths so that when I migrate from Dev to QA to Prod I don't have to do a lot of editing.
    Specifically, I want a variable to be the first part of the path for the filename (\\sundev1\fnd1-hypd1) and join this with the rest (\update\log\*.log or specific filename) using several different objects like the ODIFileMove, ODI OS Command, OS Command, etc.
    Thank you!

    Hi,
    you could set up a database table holding processing parameters (i.e. Column1 - ParamName, Column2 - ParamValue).
    One row could then be ParamName = FilePath, ParamValue = \\<server>\folder\
    So, the refreshing query (attached to a logical schema) would be something like SELECT ParamValue FROM <your table> WHERE ParamName ='FilePath'
    Then, create a variable which can refresh from the database and in the package, drop the variable onto the flow and set it's type to 'Refresh Variable' in the properties.
    Hope this helps.
    geeo

  • Setting/using a variable in a package in SQL Developer

    The 10g db I'm working with has a package that contains a variable and routines to set and get the value of the variable. The variable is used in a number of views to tailor data displayed according to the variable value. This all works well in applications, which set the variable after a connection is opened and then issue queries against the views, and then close the connection.
    This also works well in Toad - I can open Toad, run a package routine to set the value and then open views (or run queries against views) in Toad to see how different variable values effect the data displayed. The package variable maintains its value so long as Toad is open, which seems to imply that Toad keeps a connection open.
    But I can't use SQL Developer in the same way. I can run the SET routine, but it has no effect in on views subsequently run. When running the SET routine, setting the value to 1, the output is:
    Connecting to the database HERC DB.
    Process exited.
    Disconnecting from the database HERC DB.
    I can then run the GET routine, but the value of the variable is always zero:
    Connecting to the database HERC DB.
    v_Return = 0
    Process exited.
    Disconnecting from the database HERC DB.
    The implication seems to be that a connection is made, the routine is run and then the connection is closed. The closing of the connection resets the variable. Is there some way I can have SQL Developer behave like Toad, such that the package variable value is maintained for my SQL Developer session? I've looked at connection roperties and application preferences, but I've not seen anything that seems to be related keeping a connection open.
    BTW, I have tried the "connection startup script", but to no avail. Perhaps I've doen this improperly; the script simply attempts to invoke the package set routine, like so: myPkg.set_identity(1)
    Thanks.
    Edited by: user483973 on Oct 20, 2009 9:20 AM

    When running stored PL/SQL through the IDE context node or editor, indeed a new session is opened and consequently closed on completion after committing. Although great for having the IDE free to continue working, it does have its drawbacks when you want variables to persist and changes to be visible in the IDE before committing.
    To prevent the new session and the commit, just call the PL/SQL from a worksheet (in a call, query or anonymous block).
    The startup script should work in that respect, but make sure to wrap your call in an anonymous block, else you'll get a syntax error.
    Hope that helps,
    K.

Maybe you are looking for

  • Dual Display Energy Saver/One at a time

    I'm interested to know if there is any way to enable the display sleep so that it effects a dual monitor setup individually, ie. one monitor is awake, while the other one goes to sleep. Any ideas? I didn't see anything in the System Preferences that

  • Error in Running a query on ABAP web portal

    Hi Guys, We are working in a environment where BIW is installed with only WEB AS ABAP. We do not have enterprise portal in our landscape. so we need to run our reports on url http: host:8000\sap\bw\Bex? Query=........ But when we run a query fro Quer

  • Greater Than &gt in Hana?

    Context: I have a Ms Sql Statement inside a xml file and I have a conditional with a "Greater Than" comparison, so because this within a XML File I can't use the regular syntax for "Greater Than" ( > ) then I use the (>) Ms Sql Server Statement <Quer

  • JSF 2.0: Facelets: No tag libraries (TLDs)?

    Hi, I'm currently concerned with JSF 2.0 and Facelets. I found: - Tags are no longer defined in taglibs (TLDs) (instead they appear to be hard-coded in Java code) - On the other hand, jsf-impl.jar does ship two taglibs (for HTML and JSF Core), howeve

  • Increase the reliability of Acrobat XI OCR?

    I wrote this in the Illustrator forum: I've got a PDF that seems to open OK in Illustrator, it was originally produced by a CAD program: http://www.bavariayacht.info/downloads/Schematic%20Panel%2020.pdf However, none of the text is rendered as text,