Get a list of all functions and procedures in an Oracle database
Asked Answered
P

3

67

I'm comparing three Oracle schemas.

I want to get a list of all the functions and procedures used in each database. Is this possible via a query? (preferably including a flag as to whether they compile or not)

Ideally it would be great to have a single query with a flag that states whether the function/procedure is in each schema. But even just the first bit would be better than manually inspecting each schema.

Pahl answered 30/11, 2009 at 12:11 Comment(0)
Z
138
SELECT * FROM ALL_OBJECTS WHERE OBJECT_TYPE IN ('FUNCTION','PROCEDURE','PACKAGE')

The column STATUS tells you whether the object is VALID or INVALID. If it is invalid, you have to try a recompile, ORACLE can't tell you if it will work before.

Zuniga answered 30/11, 2009 at 12:14 Comment(5)
'TABLE' Can someone give a hint how to delete functions/procedures/packages ?Yeomanly
drop function xxx, drop procedure xyz, drop package foobarZuniga
Someone suggested an edit to my answer, so that the SELECT statement would only select OBJECT_NAME instead of *. Anyway, this edit has been rejected (by reviewers other than me); IMO, at least, OBJECT_NAME, OBJECT_TYPE, STATUS should be selected to get useful output. That said, SELECT * doesn't hurt in this context.Zuniga
If you have multiple users, and only like to list out objects on that user, just add in another clause "AND OWNER =[THAT USER NAME] ". Example for "user1": SELECT * FROM ALL_OBJECTS WHERE OBJECT_TYPE IN ('FUNCTION','PROCEDURE','PACKAGE') AND OWNER = 'user1'Tepic
This answer is insufficient if you want to compare functions and procedures within a package.Teresetereshkova
D
9

Do a describe on dba_arguments, dba_errors, dba_procedures, dba_objects, dba_source, dba_object_size. Each of these has part of the pictures for looking at the procedures and functions.

Also the object_type in dba_objects for packages is 'PACKAGE' for the definition and 'PACKAGE BODY" for the body.

If you are comparing schemas on the same database then try:

select * from dba_objects 
   where schema_name = 'ASCHEMA' 
     and object_type in ( 'PROCEDURE', 'PACKAGE', 'FUNCTION', 'PACKAGE BODY' )
minus
select * from dba_objects 
where schema_name = 'BSCHEMA' 
  and object_type in ( 'PROCEDURE', 'PACKAGE', 'FUNCTION', 'PACKAGE BODY' )

and switch around the orders of ASCHEMA and BSCHEMA.

If you also need to look at triggers and comparing other stuff between the schemas you should take a look at the Article on Ask Tom about comparing schemas

Dinahdinan answered 30/11, 2009 at 12:18 Comment(0)
G
4
 SELECT * FROM all_procedures WHERE OBJECT_TYPE IN ('FUNCTION','PROCEDURE','PACKAGE') 
 and owner = 'Schema_name' order by object_name

here 'Schema_name' is a name of schema, example i have a schema named PMIS, so the example will be

SELECT * FROM all_procedures WHERE OBJECT_TYPE IN ('FUNCTION','PROCEDURE','PACKAGE') 
and owner = 'PMIS' order by object_name

enter image description here

Ref: https://www.plsql.co/list-all-procedures-from-a-schema-of-oracle-database.html

Ganef answered 27/7, 2020 at 7:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.