package containing global variables throws exception ORA-04068: existing state of packages has been discarded

Posted on 2014-07-17
Last Modified: 2014-12-07
1. There is no change recompilation of package and still the package throws exception
2. Does package get recompiled when procedure in package is called from application
Question by:Saggi
    LVL 76

    Assisted Solution

    by:slightwv (䄆 Netminder)
    It looks like a few things can cause this.

    Check out the following note on Oracle Support:
    ORA-04068 Errors From User-Written And Oracle Packages (Doc ID 106206.1)

    Yes, the package should get recompiled on the next execution.
    LVL 13

    Accepted Solution

    The main problem/reason is the use of global variables within packages. Doing so, the packages "get" an internal state which can and will be invalidated upon certain situations (see below)...

    First of all the official docs which also refer to that problem (though you have to read between the lines):
    see chapter "Package Invalidations and Session State" or search for the ORA error

    The following 2 links describe the "real"/core problem quite well and offer corresponding solutions:

    This is an artefact of how Oracle maintains the internal package state. A package with no global variable has no internal state, and when it is recompiled Oracle knows it does not have to throw an ORA-04068 if the package is accessed again in the same session.

    However, a package with internal state (caused by having a package global variable) will lose that state when it is recompiled, causing the ORA-04068.
    LVL 16

    Assisted Solution

    by:Wasim Akram Shaik
    I have had this encountered before in Even after recompiling this doesn't solve the problem.. We had worked out like this
    1.(check in V$Access and kill all the sessions which are accessing that package ..might have to do this again and again to kill all accessing sessions and Flush Shared Pool)
    2. Simpler option would be to Bounce the database  and run utlrp (downtime required.. Confirm  with relevant stakeholders before proceeding with this activity)

    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
    I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
    This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
    This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now