[Last Call] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2014-07-17
Medium Priority
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 78

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 664 total points
ID: 40201858
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 14

Accepted Solution

Alexander Eßer [Alex140181] earned 672 total points
ID: 40201934
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:

from http://betteratoracle.com/posts/34-avoiding-ora-04068-existing-state-of-packages-has-been-discarded:
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
Wasim Akram Shaik earned 664 total points
ID: 40203226
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

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses
Course of the Month18 days, 15 hours left to enroll

834 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