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

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
SaggiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
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.
0
Alexander Eßer [Alex140181]Software DeveloperCommented:
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):
http://docs.oracle.com/cd/E11882_01/appdev.112/e41502/adfns_packages.htm
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.

http://technology.amis.nl/2012/08/07/reduce-occurrence-of-ora-04068-while-upgrading-plsql-packages-by-moving-global-variables-to-application-context/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Wasim Akram ShaikCommented:
I have had this encountered before in 10.2.0.4.. 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)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.