Skip to Main Content
  • Questions
  • Invalid Objects X sys.order_object_by_dependency

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Andre, from Brazil.

Asked: August 24, 2001 - 4:46 pm UTC

Last updated: November 04, 2005 - 3:31 am UTC

Version: 817

Viewed 1000+ times

You Asked

Hi Tom.
I have the following script that is very good to recompile invalid objects and I can filter
just for INVALID objects.

SET PAGESIZE 1000
SET HEAD OFF PAGES 0 LINES 79 VERIFY OFF ECHO OFF
SELECT DECODE( object_type, 'PACKAGE BODY',
'ALTER PACKAGE ' || owner||'.'||object_name || ' COMPILE BODY;',
'ALTER ' || object_type || ' ' || owner||'.'||object_name || ' COMPILE;' )
FROM sys.dba_objects a, sys.order_object_by_dependency b
WHERE a.object_id = b.object_id(+)
AND status = 'INVALID'
AND owner=upper('&OWNER')
AND object_type IN ( 'PACKAGE BODY', 'PACKAGE', 'FUNCTION', 'PROCEDURE',
'TRIGGER', 'VIEW' )
ORDER BY dlevel desc, object_type, object_name;
set head on

In 8.1.7 the view sys.order_object_by_dependency does not exists. So, Oracle recommends
to use scripts for recompiling all schema instead recompiling only INVALID objects.

Do you have a script that :
- compile just INVALID objects in 8.1.7 and
- compile in order by dependency ?

TKS.




and Tom said...

Yes, actually in my book I have this. The source code is available from:

</code> http://www.wrox.com/Books/Book_Details.asp?ISBN=1861004826 <code>

under "download code". The fact is -- you do not need to compile them in order -- you just need to compile them in some order.

1) What I do is find an invalid object
2) remember in a temp table that i've processed it
3) compile it
4) Using a brand new query find the next invalid object to compile that i haven't processed already.

So, if I have procedure A that calls procedure B and both procedure A and B are invalid, it doesn't matter if I compile B and then A -- or just compile A (compiling A will in fact compile B for me!)

If you want all of the details -- they are in the book.

Rating

  (5 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Tks !

Andre, from Brazil, August 24, 2001 - 6:24 pm UTC


Pushparaj Arulappan, November 07, 2002 - 1:08 pm UTC

Tom,

I have a situation where I need to compile the objects
in the order. Please consider the following example,

SQL > CREATE OR REPLACE TYPE object_type1
AS OBJECT ( col1 NUMBER )
/
Type created.

SQL > CREATE OR REPLACE TYPE nested_table1
AS TABLE OF ( col1 object_type1 )
/
Type created.

SQL > CREATE OR REPLACE TYPE object_type2
AS OBJECT ( col1 nested_table )
/
Type created.


For example, if I want to do any modification to the
object_type1 object..

SQL > CREATE OR REPLACE TYPE object_type1 (col1 number(4))
/
*
ERROR at line 1:
ORA-02303: cannot drop or replace a type with type or table dependents

So I have to drop all the dependents and recreate all of them in the order.

Or

SQL > DROP TYPE object_type FORCE
/
Type Dropped.

SQL > CREATE OR REPLACE TYPE object_type1 (col1 number(4))
/
Type created.

If I drop the object using FORCE option, and re-creating that object alone gives internal error problem when the dependent objects are accessed from the XML application.

1) Is there any way to compile a object type which has dependent objects without droping.

2) Do you have a sample sql which can get all the nested dependents in the for a given object. (ie object_type3 is dependent on nested_table1 which is dependent on object_type1.)

Thanks
Pushparaj

Tom Kyte
November 07, 2002 - 1:19 pm UTC

1) upgrade to 9i where types are modifiable (type evolution is fully supported).

2) you would use user_dependencies to find that information -- i don't not have an off the shelf query for you in that case.



Is there a bug in the compile script ?

A Reader, March 26, 2003 - 11:06 am UTC

Tom,

When I download the script, run against Sys, then try and use from another schema, I get:

SQL> exec sys.compile_schema('ABC');
alter PACKAGE BODY DW.ABC compile body
ORA-00922: missing or invalid option

(repeated for a whole series of packages)

I suspect its because the script selects the object type, when for packages it should just be:

alter PACKAGE DW.ABC compile body ???

I modified the script to do a decode on object type up-front and if it is package body replace it with package.

Did I miss something - that seems to work now ? 

Tom Kyte
March 26, 2003 - 4:00 pm UTC

yes, my script did not get 100% of the types available over time. adding support for it as you did is proper

How to modify the object/type?

JD, November 03, 2005 - 5:15 pm UTC

Tom,

You have mentioned in the followup:
--
1) upgrade to 9i where types are modifiable (type evolution is fully supported).
--

Could you please share the syntax/documentation URL? Would it work in 9.0.2?

I would like to avoid the error message "ORA-02303" while using CREATE OR REPLACE.

Thanks in advance,

JD



Tom Kyte
November 04, 2005 - 3:31 am UTC

Thanks

JD, November 04, 2005 - 10:31 am UTC


More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library