When should be package invalidated?

Hello guys,
I would need again some help...
My question is: When exactly should be package invalidated?
Consider following situation:
We have two packages, one contains constants (in its specification), the other is reading these constants. Package is reading these constants in package body and package spec as well. Now, when I add a new constant to the first package and recompile it, should this invalidate the other package??? The new added constant is not used in the other package.
In reality, we have a Constant package, containing all constants in its specification. One package (test_pkg) is reading some constant let say form line 100. Now we add new constant let say to line 50. When we recompile the constant package, planty of packages get invalidated because they are reading from it. We recompile all invalid packages. However test_pkg is not invalidated!!! Now if we run the code from test_pkg, it is still reading the constant from line 100, so it is reading it from wrong place and the constant has wrong value! The only thing what help is to recompile the test_pkg.
So it looks like the reference to Constant package wasn't updated.
Why isn't test_pkg invalidated???
Oracle version:
SELECT * FROM V$VERSION;
Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
"CORE     11.2.0.1.0     Production"
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

From my standard library of responses...
Packages tend to fail because of their "package state". A package has a "state" when it contains package level variables/constants etc. and the package is called. Upon first calling the package, the "state" is created in memory to hold the values of those variables etc. If an object that the package depends upon e.g. a table is altered in some way e.g. dropped and recreated, then because of the database dependencies, the package takes on an INVALID status. When you next make a call to the package, Oracle looks at the status and sees that it is invalid, then determines that the package has a "state". Because something has altered that the package depended upon, the state is taken as being out of date and is discarded, thus causing the "Package state has been discarded" error message.
If a package does not have package level variables etc. i.e. the "state" then, taking the same example above, the package takes on an INVALID status, but when you next make a call to the package, Oracle sees it as Invalid, but knows that there is no "state" attached to it, and so is able to recompile the package automatically and then carry on execution without causing any error messages. The only exception here is if the thing that the package was dependant on has changes in such a way that the package cannot compile, in which case you'll get an Invalid package type of error.
And if you want to know how to prevent discarded package states....
Move all constants and variables into a stand-alone package spec and reference those from your initial package. Thus when the status of your original package is invlidated for whatever reason, it has no package state and can be recompiled automatically, however the package containing the vars/const will not become invalidated as it has no dependencies, so the state that is in memory for that package will remain and can continue to be used.
As for having package level cursors, you'll need to make these local to the procedures/functions using them as you won't be able to reference cursors across packages like that (not sure about using REF CURSORS though.... there's one for me to investigate!)
This first example shows the package state being invalided by the addition of a new column on the table, and causing it to give a "Package state discarded" error...
SQL> set serveroutput on
SQL>
SQL> create table dependonme (x number)
  2  /
Table created.
SQL>
SQL> insert into dependonme values (5)
  2  /
1 row created.
SQL>
SQL> create or replace package mypkg is
  2    procedure myproc;
  3  end mypkg;
  4  /
Package created.
SQL>
SQL> create or replace package body mypkg is
  2    v_statevar number := 5; -- this means my package has a state
  3
  4    procedure myproc is
  5      myval number;
  6    begin
  7      select x
  8      into myval
  9      from dependonme;
10
11      myval := myval * v_statevar;
12      DBMS_OUTPUT.PUT_LINE('My Result is: '||myval);
13    end;
14  end mypkg;
15  /
Package body created.
SQL>
SQL> exec mypkg.myproc
My Result is: 25
PL/SQL procedure successfully completed.
SQL>
SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
  2  /
OBJECT_NAME
OBJECT_TYPE         STATUS
MYPKG
PACKAGE             VALID
MYPKG
PACKAGE BODY        VALID
SQL>
SQL>
SQL> alter table dependonme add (y number)
  2  /
Table altered.
SQL>
SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
  2  /
OBJECT_NAME
OBJECT_TYPE         STATUS
MYPKG
PACKAGE             VALID
MYPKG
PACKAGE BODY        INVALID
SQL>
SQL> exec mypkg.myproc
BEGIN mypkg.myproc; END;
ERROR at line 1:
ORA-04068: existing state of packages has been discarded
ORA-04061: existing state of package body "SCOTT.MYPKG" has been invalidated
ORA-06508: PL/SQL: could not find program unit being called: "SCOTT.MYPKG"
ORA-06512: at line 1
SQL>
SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
  2  /
OBJECT_NAME
OBJECT_TYPE         STATUS
MYPKG
PACKAGE             VALID
MYPKG
PACKAGE BODY        INVALID
SQL>
SQL> exec mypkg.myproc
PL/SQL procedure successfully completed.
SQL>
SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
  2  /
OBJECT_NAME
OBJECT_TYPE         STATUS
MYPKG
PACKAGE             VALID
MYPKG
PACKAGE BODY        VALIDAnd this next example shows how having the package variables in their own package spec, allows the package to automatically recompile when it is called even though it became invalidated by the action of adding a column to the table.
SQL> drop table dependonme
  2  /
Table dropped.
SQL>
SQL> drop package mypkg
  2  /
Package dropped.
SQL>
SQL> set serveroutput on
SQL>
SQL> create table dependonme (x number)
  2  /
Table created.
SQL>
SQL> insert into dependonme values (5)
  2  /
1 row created.
SQL>
SQL> create or replace package mypkg is
  2    procedure myproc;
  3  end mypkg;
  4  /
Package created.
SQL>
SQL> create or replace package mypkg_state is
  2    v_statevar number := 5; -- package state in seperate package spec
  3  end mypkg_state;
  4  /
Package created.
SQL>
SQL> create or replace package body mypkg is
  2    -- this package has no state area
  3
  4    procedure myproc is
  5      myval number;
  6    begin
  7      select x
  8      into myval
  9      from dependonme;
10
11      myval := myval * mypkg_state.v_statevar;  -- note: references the mypkg_state package
12      DBMS_OUTPUT.PUT_LINE('My Result is: '||myval);
13    end;
14  end mypkg;
15  /
Package body created.
SQL>
SQL> exec mypkg.myproc
My Result is: 25
PL/SQL procedure successfully completed.
SQL>
SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
  2  /
OBJECT_NAME
OBJECT_TYPE         STATUS
MYPKG
PACKAGE             VALID
MYPKG
PACKAGE BODY        VALID
SQL>
SQL> alter table dependonme add (y number)
  2  /
Table altered.
SQL>
SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
  2  /
OBJECT_NAME
OBJECT_TYPE         STATUS
MYPKG
PACKAGE             VALID
MYPKG
PACKAGE BODY        INVALID
SQL>
SQL> exec mypkg.myproc
My Result is: 25
PL/SQL procedure successfully completed.

Similar Messages

  • Invalid Namespace when trying to package AIR application

    I am using a self-signed certificate when trying to package
    my application, but when I run the command to package it I get the
    following error: "Invalid namespace
    http://ns.adobe.com/air/application/1.0"
    Then it leaves a .tmp file in the directory where I ran the
    batch file containing the package statement.
    What should be done from here?

    Check which version of adt you are using. Sounds like you are
    using a beta release, which wouldn't recognize the final 1.0
    namespace.
    Oliver Goldman | Adobe AIR Engineering

  • When should you update a package

    I've been using arch for a couple of months now, and only did a full update the day I installed arch.
    The reason I haven't done a update yet is because I am scared I'm gonna screw up my pc
    So I got some newb questions:
    1: Is it smart to do a full update?
    2: When should you do an update?
    3: Where can I find the source of an old package?
    4: If I do an update, should I backup anything?
    -- thanks in advance --
    Last edited by disparv (2012-01-12 19:58:54)

    disparv wrote:
    I've been using arch for a couple of months now, and only did a full update the day I installed arch.
    The reason I haven't done a update yet is because I am scared I'm gonna screw up my pc
    So I got some newb questions:
    1: Is it smart to do a full update?
    2: When should you do an update?
    3: Where can I find the source of an old package?
    4: If I do an update, should I backup anything?
    -- thanks in advance --
    My very personal answers.
    1. Yes ! (but read below)
    2. Personal answer. If you need a feature present in the next version of a package for example.
    3. If you need a precompiled old package read: https://wiki.archlinux.org/index.php/Do … g_Packages. If you want the source of an old package, you can get old build script by svn: http://www.archlinux.org/svn/ .
    4. Many people will say no. But, especially if core packages will be updated, I backup the whole system on a hard disk before updating.
    Bear also in mind that you cannot usually mix old and new packages (If you downgrade a particular package and that nothing depends on it and if the old version is still functioning, there is no problems; but if you completely mix old and new packages, including libraries you will have problems).

  • When should I expect my new phone.

    Ordered a new phone online on Saturday.  When should I most likely expect to receive it?

    You'll receive a notification when your order ships, and with that you'll get a tracking number that you can use to follow the package until it arrives.  How quickly the phone comes will depend on if it is in stock and what type of shipping you paid for.

  • When should we expect album art support on Zen microph

    When Should we expect support for album art and ease of looking at photos while playing music. I am very disappointed at the lack of this specific firmware upgrade. I hope to see it soon on the Zen MicroPhoto.

    Snoweagle wrote:
    U're right...i also didn't use the Mediasource software that comes with the package, all i did was simply dragging n dropping. This makes it very easy to transfer songs on any computers with Windows XP, just bring the USB cable that's all.
    With Windows XP, Service Pack and Windows Media Player 0, to be exact. ;-)

  • Please specify how do we can activate a web scope feature over all sub webs when a solution package is activated.???

    please specify how do we can activate a web scope feature over all sub webs when a solution package is activated.
    when a solution package is deactivated the web scope features over all sub website gone deactivated and does not re-activated when solution package is activated.
    we have couples of sub webs to activate web features manually that should be activated when a solution package is activated.
    all sub webs are created by custom web templates onet.xml.

    Hi,
    I can think of three different solution (all custom solution)
    Use Powershell Cmdlet to activate feature to all sub sites
    Upgrade your solution to Site Collection scope, However all subsites under the root will have access to the features, which you may want to restrict based on your requirement
    create a site scoped solution feature to activate the web scoped features, this will give you more control and easier management of all your features
    here are some links -
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/10a95745-67c5-4a32-a783-b9ae8977f7e0/deploying-a-solution-with-a-feature-to-be-activated-on-a-number-of-subsites?forum=sharepointdevelopmentprevious
    http://sharepointgroup.wordpress.com/2012/05/04/activating-and-deactivating-features-with-powershell/
    Hope this helps!
    Ram - SharePoint Architect
    Blog - SharePointDeveloper.in
    Please vote or mark your question answered, if my reply helps you

  • When we use package's begin part?

    Guys, I would like to learn when we use this part of package. I mean, because begin part only executes ones and never executes again in that session. So why we use this part?
    create or replace
    package body my_pack
    is
      num number;
      str varchar2(50);
    begin
      So when should we use this part of packages?????
      dbms_output.put_line(Why we use this part??????');
    end;Thanks

    >
    So in the example above of a logging interface, if another package also use the same interface then it will overwrite the verbosity level of the initial package that was loaded. In such a case, each procedure in a package will need to first set the log level prior to using application logging.
    >
    That sounds like a design and implementation issue - not the way I implement logging. It doesn't make sense to have each package potentially overwrite the global log level like this. A package would either use the global log level already set or use it's own level.
    The logging package would have an 'init' section that checks for a context variable to set the logging level and then either uses it or a default value if none is set. The log procedures would also be overloaded so that if no log level was specified as a parameter then the global value (set by the log package init section) would be used. The overloaded procedure would accept a log level parameter so that different levels could be used as needed.
    The 'init' section in other packages would also check for a context variable (one for their package) and use it if it had been set. Otherwise they would get their log level from the value already set by the log package. If this 'other' package was the first to call the log package then they would get the value set by the log package 'init' as explained.

  • When do indexes become invalid?

    When do indexes become invalide?

    Indexes can become invalid or unusable whenever a DBA tasks shifts the ROWID values, thereby requiring an index rebuild. These DBA tasks that shift table ROWID's include:
    Table partition maintenance - Alter commands (move, split or truncate partition) will shift ROWID's, making the index invalid and unusable.
    CTAS maintenance - Table reorganization with "alter table move" or an online table reorganization (using the dbms_redefinition package) will shift ROWIDs, creating unusable indexes.
    Oracle imports - An Oracle import (imp utility) with the skip_unusable_indexes=y parameter
    SQL*Loader (sqlldr utility) - Using direct path loads (e.g. skip_index_maintenance) will cause invalid and unusable indexes.
    Cheers

  • Known issue: Speech APIs fail when an x86 package is run on an x64 desktop (Windows 10 Insider Preview SDK and tools, April 2015 release)

    When building an app for the x86 platform, speech APIs fail when the x86 package is run on the desktop of an x64 system. You may see an error with the message "mod not found".

    Use the Visual Studio Configuration Manager to retarget the app to x64 when running on an x64 system.

  • When should we go for PreOperation in dynamics crm plugin

    i registered more plugin on Post operation.create,update,retrieve,retrievemultiple.Now when should i go for Pre-Operation plugin 
    Tell some Some scenarious for this Pre-Operation Stage?
    hsk srinivas

    I believe difference is obvious. Pre plugin is called before information is stored in CRM DB. Post plugin is called after. Recheck following description -
    http://msdn.microsoft.com/en-us/library/gg327941.aspx
    Dynamics CRM MVP/ Technical Evangelist at
    SlickData LLC
    My blog

  • When should message protocol be FILE CONTENT CONVERSION

    HI one and all,
    What doubt keeps haunting me is when should message protocol be selected FILE CONTENT CONVERSION.
    for what format of sender information IS THIS USED ?
    Ur answer is awaited.
    Thanking you,
    Ranjith.

    Ranjith,
    Consider the below cases u are sending XML file as
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:Test_MT xmlns:ns0="urn:test">
       <EmpProfile_Msg>
          <Empno>1001</Empno>
          <EmpName>J</EmpName>
          <DepartmentName>SAP</DepartmentName>
       </EmpProfile_Msg>
    </ns0:Test_MT>
    But while writing the output u need the file as
    1000 , J, SAP
    Then u have to go for File Content Conversion at the Receiver adapter.
    Similarly ,consider the other way around u are sending the file input as
    1000 , J, SAP   and u want XML , then u have to do FCC in sender adapter.
    Hope it clears!!!
    Best regards,
    raj.

  • I ordered my iphone 5s on wednesday and it still says its being processed but it was overnight shipping so when should it come

    I ordered my iphone 5s on Wednesday. The order tracker says it is still being processed. The shipping was overnight shipping. When should it be here?

    As your order moves through the process, you can check the status at http://bit.ly/RjmCUB. You may not be able to see a change from Processing until it officially ships, then you'll see the tracking number. If you've received a confirmation email that your order was submitted, any additional information throughout the fulfillment process will be sent to that same email address.
    VanetrisC_VZW
    Follow us on Twitter @VZWSupport

  • When should I use static variable and when should not? Java essential

    When should I use static variable and when should not? Java essential

    Static => same value for all instances of the class.
    Non-static => each instance can have its own value.
    Which you need in which circumstances is completely up to you.

  • What is the necessity of the AC power cord (with Mac Book Air)? When should it be used with the power adapter?

    what is the necessity of the AC power cord (with the Mac book Air)? when should it be used?

    Gary, you wouldn't believe some of the questions people ask on this site.
    Why are both cords necessary?
    They are not.
    Other than the two reasons dominic23 sited are there any other reasons to use the AC power cord rather than the power adapter cord alone?
    No.

  • What is a Transient Variable and when should it be used

    Hello everyone,
    I just want to know the details regarding the transient variable and when should we use it. what is the significance of this variable?

    Transient variables are not written out when the class is serialized.
    http://java.sun.com/docs/books/tutorial/essential/io/providing.html

Maybe you are looking for

  • Macbook Pro to Projector issue. Please help.

    Hey now. I have been watching tv via a projector using my macbooks for years now. Today all of a sudden it doesn't work anymore. I don't know if it has to do with an apple update I downloaded. Curiously, I can see my computer's wallpaper through the

  • PowerPoint to PDF creates "blank" pages

    I just downloaded Acrobat 9 this afternoon and have tried several times to convert a very large PowerPoint presentation to a PDF file.  One time is said "unexpected error" mesaage, so I shut down and restarted.   The second time, it made the PDF file

  • How to add Change Layout Button to ALV Toolbar?

    Hi All, I am using a SAP GUI STATUS 'STANDARD' that has almost all the funcationality needed except for the change layout button. I have tried changing the GUI STATUS to 'STANDARD_FULLSCREEN' which has the button I am looking for but it does not show

  • Spacing inverted commas - quotation marks

    En English there is no spacing between quotations marks and the word famed, like "quotation marks", but in French there is a spacing like : " guillemets ". I write in French, so how can I create a permanent spacing between quotations marks and the wo

  • .mov files are now renamed

    Why are my .mov files suddenly getting renamed when I add them to Keynote? They used to retain their original names. Very confusing now.