List of Oracle views using specific table name - oracle

I wish to find a list of all views under specific schema using mentioned table name.
e.g. if view1 and view2 uses table1, using table name "table1", I wish to find view names "view1" and view2".
Please let me know, how can I do it.

select
*
from
all_dependencies
where
type='VIEW'
and referenced_name like '%table_name%'
and referenced_type = 'TABLE'

Use this query:
SELECT *
FROM all_dependencies
WHERE TYPE = 'VIEW'
AND referenced_type = 'TABLE'

Related

Where is this Oracle object?

I have some SQL scripts; one of them references an object called "names". I can:
select * from names
and it returns results. However, I cannot see a table called "names". Neither can I see a view called "names". I can't find a custom type called "names".
If I look for one of the columns that is returned by the query select * from names using:
select * from sys.all_tab_columns where column_name like '%MyColumn%'
it finds a table called LSNAMES, but that has no rows.
Any ideas how I can find this "table"?
I'd start the research with understanding what type of object this is:
SELECT owner, object_name, object_type
FROM all_objects
WHERE object_name = 'NAMES'
Once you have a type, you could query some more information from all_<type>s
Look for:
A materialized view called NAMES
SELECT * FROM ALL_MVIEWS WHERE MVIEW_NAME = 'NAMES';
A synonym called NAMES
SELECT * FROM ALL_SYNONYMS WHERE SYNONYM_NAME = 'NAMES';

Find which oracle database object inserts data into a particular table?

I want to find the name of the stored procedure, package, function or trigger which is inserting data into a particular table, is there any inbuilt object so that i can use it. I am searching the name of the object from last 2 hours. Kindly help.
You cannot find the inserted PL/SQL block, but you can try out to identify the procedures/functions referring it. And increase your chances of finding.
select
proc_syn.nam,
proc_syn.referenced_owner,
proc_syn.referenced_name,
proc_syn.referenced_type,
syn_tab.table_name
from
dba_dependencies proc_syn, dba_synonyms syn_tab, dba_tables tables
where
REFERENCED_TYPE in ( 'SYNONYM','TABLE')
AND proc_syn.referenced_name = syn_tab.synonym_name
AND syn_tab.synonym_name = tables.table_name
AND syn_tab.owner = 'PUBLIC'
AND REFERENCED_NAME = 'YOUR_TABLE_NAME'
order by
proc_syn.referenced_owner, syn_tab.table_name;
The above query would return the table objects, that refer this table.
Note, this would return, when you use STATIC queries only. Any dynamic queries, is completely out of hand.
You can try by analyzing all the source of your DB with something like this:
select *
from dba_source
where upper(text) like '%TABLE_NAME%'
The pro of this approach is that you will get even dynamic code; the con is that you'll have even select, update, ...
If the table is statically referenced you can check the ALL_DEPENDENCIES view
SELECT * FROM ALL_DEPENDENCIES WHERE REFERENCED_NAME = '<your table>';
This will find all usages, not only insert
You can also search within source code:
SELECT * FROM ALL_SOURCE WHERE UPPER(TEXT) LIKE '%INSERT%<your table>%'
This will find the usage only if INSERT and your table are on the same line.
However if the command is built more dynamically then you will not find it that simply.
You can use user_source or user_dependencies table as below.
Using table user_source
select * from user_source
where upper(text) like '%<YOUR TABLE NAME in UPPER CASE>%'
You can select from user_source , all_source , dba_source depending on user you have logged in and permission that user have.
Using table user_dependencies
SELECT NAME FROM user_dependencies WHERE referenced_name = '<YOUR TABLE NAME in UPPER CASE>'
UNION
SELECT referenced_name FROM user_dependencies WHERE name = '<YOUR TABLE NAME in UPPER CASE>'
You can select from user_dependencies , all_dependencies , dba_dependencies depending on user you have logged in and permission that user have.

Oracle query that will list of the database objects referenced by a view

Is there an Oracle view that will list all of the database objects referenced by the DDL of a given view, procedure, or function?
So if a view is defined as:
CREATE OR REPLACE VIEW_B AS
SELECT * FROM TABLE_A INNER JOIN VIEW_A
running a query on this system view:
SELECT REF_OBJECT_NAME, REF_OBJECT_TYPE FROM V$XXX WHERE OBJECT_NAME='VIEW_B'
would list something like:
REF_OBJECT_NAME REF_OBJECT_TYPE
TABLE_A TABLE
VIEW_A VIEW
Try:
select * from dba_dependencies
where owner = 'view owner'
and name = 'view name';

How to track which tables/views/etc depends from a table, in Oracle

How to know which objects (tables/views/etc) uses a certain table?
I have to replace my table PRICE.
So, is there something like?
select system.dependencies from PRICE
SELECT NAME
from user_dependencies
where referenced_name = 'PRICE'

Oracle: Is there a way to get the column data types for a view?

For a table in oracle, I can query "all_tab_columns" and get table column information, like the data type, precision, whether or not the column is nullable.
In SQL Developer or TOAD, you can click on a view in the GUI and it will spit out a list of the columns that the view returns and the same set of data (data type, precision, nullable, etc).
So my question is, is there a way to query this column definition for a view, the way you can for a table? How do the GUI tools do it?
You can use user_tab_columns (or all_tab_columns and dba_tab_columns respectively) regardless if table_name refers to a view or a table.
View columns appear in all_tab_columns, so you can query them just as you can tables.
Just simply write this query:
SQL> desc TABLE/VIEW NAME;
For example if the table/view name is "department" Then just write:
SQL> desc department;
This will give the list of all fields, it's type and default Null info of the table or view.
you can use the ANSI catalog views, should work for most RDBMs
select *
from information_schema.columns c
join information_schema.tables t on c.table_name = t.table_name
where table_type = 'view'

Resources