• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 512
  • Last Modified:

Issue with repeating execution of the same procedure.

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
GoodName
Asked:
GoodName
  • 4
  • 4
3 Solutions
 
Naveen KumarProduction Manager / Application Support ManagerCommented:
can you paste your procedure code please ?
0
 
Naveen KumarProduction Manager / Application Support ManagerCommented:
may be your procedure is altering ( issuing some ddl ) which is invalidating this procedure.
0
 
Jinesh KamdarCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
GoodNameAuthor Commented:
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
 
GoodNameAuthor Commented:
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
 
Naveen KumarProduction Manager / Application Support ManagerCommented:
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
 
GoodNameAuthor Commented:
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
 
Naveen KumarProduction Manager / Application Support ManagerCommented:
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
 
GoodNameAuthor Commented:
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now