Solved

sql to find references to a table

Posted on 2012-04-11
13
445 Views
Last Modified: 2012-04-30
hi

Is there a sql to find out all the store procedures which are using a table?

thanks
0
Comment
Question by:royjayd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
  • +1
13 Comments
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 143 total points
ID: 37832741
The view you need is DBA_DEPENDENCIES.

http://www.dba-oracle.com/d_dba_dependencies.htm
0
 
LVL 8

Assisted Solution

by:Christoffer Swanström
Christoffer Swanström earned 72 total points
ID: 37832811
SELECT
  *
FROM
  dba_dependencies
WHERE
  referenced_name = 'YOUR_TABLE_NAME'
AND
  type IN ('PACKAGE BODY', 'PROCEDURE', 'FUNCTION')
;

This will show you all packages, procedure and functions that reference your table.

Note that you will NOT be able to find procedures, functions or packages that reference a table using dynamic SQL. E.g. if your procedure contains EXECUTE IMMEDIATE 'TRUNCATE YOUR_TABLE_NAME', the above query will not show this dependency.
0
 
LVL 8

Assisted Solution

by:Christoffer Swanström
Christoffer Swanström earned 72 total points
ID: 37832831
If you want to find procedure, functions or packages where the name of the table is hard coded in a dynamic SQL statement you can query all_source:

SELECT
  *
FROM
  all_source
WHERE
  UPPER(text) LIKE '%YOUR_TABLE_NAME%'
;

Of course this will only find the cases where the table name is hard coded. If it is passed as an argument or otherwise generated dynamically you will not find it.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:royjayd
ID: 37833133
thanks

when i do
SELECT
  *
FROM
  dba_dependencies
WHERE
  referenced_name = 'PERSON_DATA'  AND
  type IN ('PACKAGE BODY', 'PROCEDURE', 'FUNCTION')
;

i get error table does not exist

however when i replace dba_dependencies with all_dependencies
i get some results

why is that
0
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 143 total points
ID: 37833247
"dba_" level views require DBA level access and show EVERYTHING in the database

"all_" level views are the objects you own and have rights to access

"user_" views are the objects you own.
0
 
LVL 32

Assisted Solution

by:awking00
awking00 earned 35 total points
ID: 37833257
It's because you don't have permissions to access the dba dictionary tables or views. You need to have the 'select any dictionary' privilege.
0
 

Author Comment

by:royjayd
ID: 37833398
>>>It's because you don't have permissions to access the dba dictionary tables or views. You need to have the 'select any dictionary' privilege.


what exactly do you mean by dictionary ? Do you mean schema ?


thx all.
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37833415
The data dictionary are all the system views/tables about things (metadata).  A schema is a user that owns objects.  Two different things.

http://en.wikipedia.org/wiki/Data_dictionary
0
 

Author Comment

by:royjayd
ID: 37834630
one quick question

when i run
SELECT * FROM all_dependencies WHERE  referenced_name = 'GET_STATUS' AND type IN ('PACKAGE BODY', 'PROCEDURE', 'FUNCTION', 'TYPE');

i get no data found

But i see 'GET_STATUS' is defined under function which is being used by a procedure body.

any idea why?
0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 143 total points
ID: 37834652
Works for me:
create or replace function myfunc return varchar2 
is
begin
	return 'Hello';
end;
/

show errors

create or replace procedure myproc
is
begin
	dbms_output.put_line(myfunc);
end;
/

show errors


SELECT * FROM all_dependencies WHERE  referenced_name = 'MYFUNC' AND type IN ('PACKAGE BODY', 'PROCEDURE', 'FUNCTION', 'TYPE');

Open in new window


Does your setup resemble my test case?
0
 

Author Comment

by:royjayd
ID: 37834915
>>Does your setup resemble my test case?


Does it have to do something with grants? Do i need to have grants to all the functions ?
0
 

Author Comment

by:royjayd
ID: 37834918
and yes,.. my set up is exactly like yours
0
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 143 total points
ID: 37837326
If it was a permission issue you would get a permissions error.

Remember the ALL_ views are just objects you either own or have been granted access to.

What is the result of:
select owner, object_type from all_objects where object_name='GET_STATUS';
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
Suggested Courses

635 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