Solved

Issue with repeating execution of the same procedure.

Posted on 2007-11-28
9
498 Views
Last Modified: 2013-12-19
Hi everyone,

I have an issue executing this same procedure multiple times.

Right after compilation it works fine. When I execute the same procedure second time I gets the following error message:

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

If I run it third time (not doing anything) or explicitly recompiling it again it works. If I run it fourth time I gets the same error message from above. It seems that I have to recompile this procedure explicitly every time to avoid a system error. What could be wrong with this procedure?

Please advice.
0
Comment
Question by:GoodName
  • 4
  • 4
9 Comments
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 20371281
can you paste your procedure code please ?
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 20371291
may be your procedure is altering ( issuing some ddl ) which is invalidating this procedure.
0
 
LVL 18

Accepted Solution

by:
Jinesh Kamdar earned 200 total points
ID: 20371414
I agree with nav. Your SP must be issuing ALTER DDL statements that are referenced by the SP before/after the DDL statements which in turn invalidates the procedure itself bcoz of the dependency. Post your code.
0
 

Author Comment

by:GoodName
ID: 20375660
Thank you both for your comments.

It is hard to post my procedure because of client security requirements and because it is a package of about 4000 lines of code.

But from what you are telling I can confirm that my package has many dynamic  queries (DDL statements like CREATE, DROP, ALTER tables) which create "on a fly" ETL staging environment (a lot of temporary and permanent tables, sequences, constraints and indexes).

In this situation what I can do to prevent this package from crashing during job executions? This package is executed only as a night job to feed a data warehouse.

Please advice.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:GoodName
ID: 20378294
Hi everyone,

For now I am using DBMS_DDL.ALTER_COMPILE() utility to make a package run without this error.

But I would like to understand how I can adjust my package to avoid such situation in a first place rather then to fix it every time.

I'd appreciate any advice.

Thanks.
0
 
LVL 28

Assisted Solution

by:Naveen Kumar
Naveen Kumar earned 300 total points
ID: 20379145
If that is the case then we should have something like shown below ( just one more job -- just to compile your procedure/package before you execute it ).

job1 : -- dummy job to compile your procedure/package which is giving that error.

job2 : -- this is the job which executes your procedure. ( for sure it will not give any errors because we compile it using job1

Thanks
0
 

Author Comment

by:GoodName
ID: 20379734
Nav,

I have already created a little procedure which checks the status of the package and if it necessary compiles it before execution and it is working okay. Thank you.

But I would like to correct the package. How I can use DDL statements not turning a package status to invalid? Or it is not possible within the same package if it has references to created by DDL statements objects?

Thanks.



0
 
LVL 28

Assisted Solution

by:Naveen Kumar
Naveen Kumar earned 300 total points
ID: 20380016
By default, oracle invalidates any packages whenever you run DDL on those objects which are referenced in your package. We cannot stop this.

we can get rid of errors by compiling it before we call it.

Also let us say when some other package/procedure does some DDL ( alter to your database objects ) on which your actual package is based, then also your actual package will go invalid.

Can you execute the DDL's alone out of this package code ( is this not possible ) ?

Thanks
0
 

Author Comment

by:GoodName
ID: 20386210
Thank you, Nav.

All this recompilation is not very convenient approach to DDL functionality from Oracle.

Normally, we are trying to compile the code and save it in the cash for performance improvements (avoiding unnecessary parsings and compilations) but in this case we are enforced to..

Yes, I created another "entry level" procedure where I recompiling the ETL package prior to its execution and created a job which runs this "entry" procedure. This way, it seams more safe especially in a case if DBAs or developers need to execute the ETL process ad-hoc.

Thanks again for your help.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

707 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

17 Experts available now in Live!

Get 1:1 Help Now