English 中文(简体)
Frequent error in Oracle ORA-04068: existing state of packages has been discarded
原标题:

We re getting this error once a day on a script that runs every two hours, but at different times of the day.

ERROR at line 1:
ORA-04068: existing state of packages has been discarded
ORA-04061: existing state of package body "PACKAGE.NAME" has been
invalidated
ORA-06508: PL/SQL: could not find program unit being called:
"PACKAGE.NAME"
ORA-06512: at line 1

Could someone list what conditions can cause this error so that we could investigate?

Thanks.

UPDATE: Would executing ALTER SESSION CLOSE DATABASE LINK DBLINK invalidate a state of the package?

最佳回答

This one liner actually solved everything:

PRAGMA SERIALLY_REUSABLE;

Be sure that your global variables are stateless to avoid any issues.

问题回答

The package has public or private variables. (Right?) This variables form the state a the package. If you compile the package in 3rd session. The next access to this package will throw the ORA-04068.

The build timestamp of a package must be older than the package session state.

If the package state is not needed for script running, the call DBMS_SESSION.RESET_PACKAGE at the beginning of your script. This cleans all package states of your session.

You may also check dba_dependencies or user_dependencies.

select *
from dba_dependencies
where name =  YOUR_PACKAGE 
and type =  PACKAGE  --- or  PACKAGE_BODY 
and owner = USER --- or USERNAME

This will give you the objects your package is dependent on. Check whats happening in there.

We have had this issues for couple of times and for time being, we were compiling schema to resolve this issue temporarily. Over couple of days we were searching for the permanent resolution.

We found below query that showed timestamp difference in our synonym. we recompiled synonym and It worked !!! It s been almost a week and so far we have no issues. Here is the query that helped in our case.

**

select do.obj# d_obj,do.name d_name, do.type# d_type, po.obj# p_obj,po.name p_name,
to_char(p_timestamp, DD-MON-YYYY HH24:MI:SS ) "P_Timestamp",
to_char(po.stime , DD-MON-YYYY HH24:MI:SS ) "STIME", 
decode(sign(po.stime-p_timestamp),0, SAME , *DIFFER* ) X 
from sys.obj$ do, sys.dependency$ d, sys.obj$ po
where P_OBJ#=po.obj#(+) and D_OBJ#=do.obj# 
and do.status=1 /*dependent is valid*/ 
and po.status=1 /*parent is valid*/ 
and po.stime!=p_timestamp /*parent timestamp not match*/ 
order by 2,1;

**

I hope this helps someone who may be having this issue.

It seems that you are making changes to your objects that make other objects invalid. Droping an index for example can put into an invalid state all the packages that dependes on that table. It can have a cascade efect. If the package is invalid, the funciton that depends on the package and the view that uses the function can become invalid. Try to recompile all the objects after every DDL query.





相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

How to make a one to one left outer join?

I was wondering, is there a way to make a kind of one to one left outer join: I need a join that matches say table A with table B, for each record on table A it must search for its pair on table B, ...

Insert if not exists Oracle

I need to be able to run an Oracle query which goes to insert a number of rows, but it also checks to see if a primary key exists and if it does, then it skips that insert. Something like: INSERT ALL ...

How can I store NULLs in NOT NULL field?

I just came across NULL values in NOT-NULL fields in our test database. How could they get there? I know that NOT-NULL constraints can be altered with NOVALIDATE clause, but that would change table s ...

Type reference scope

I m studying databases and am currently working on a object-relational DB project and I ve encountered a small problem with the number of possible constraints in an object table. I m using "Database ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

热门标签