Table and Proc dependency - oracle

I am new to schema and not sure how the table is being populated (How the data is being inserted into the table ). How can we find out ?
This should work.
select *
from dba_source
where upper(text) like '%TABLE_NAME%'
But as I do not have DBA rights , can not execute this command. What is the other way to find this out ?

To see dependencies between objects you have access to you can query the all_dependencies data dictionary view. In this case:
select * from all_dependencies where referenced_name = 'YOUR_TABLE_NAME';
If the objects are in your own schema when you can use the user_dependencies view. If you want to see objects you don't have privileges against then you can use dba_dependencies, but it sounds like you are unlikely to have the privileges required to query that view, since you can't see dba_source.
Of course, that will only identify references within your stored PL/SQL code; it won't tell you about any external application code that is performing inserts directly against the database (as opposed to via CRUD procedures) or manual inserts.
And it will only tell you which objects have dependencies, you'll still need to dig through the object source code, either by querying all_source (or user_source if you're the owner) for the relevant type and name. I would avoid the possibility of false-positives from, say, comments that happen to mention the table name in code which doesn't access it. You could also do that outside the database - hopefully your code is under source control (right!?).

If you know the query you need to run but do not have the necessary privileges then perhaps you can write the query using USER_ or ALL_ views to validate the syntax then change the view to DBA_ and ask the DBA to run the query for you.

Related

How can I create a table with same attributes of a View another system delivers me?

An external system granted to my system a view named V_EXT so that I can make selections on it, reading all its content:
SELECT *
FROM V_EXT;
this view has a lot of fields and I would like to create an empty table in my system with the exactly same attributes of this view (same names and same types). Is there a way to do this without simply guessing from the content I received what each attribute is?
I am using Oracle SQL Developer.
With Code.
create table objects_copy2
as
select *
from all_objects
where 1=2; -- add this line if you want NO data, otherwise you get all the data too
With SQL Developer specifically, it's actually harder. You would need to find the underlying OBJECT(s) used in the query. Then look up those data types, and manually build out your CREATE TABLE statement.
CREATE TABLE AS SELECT is the way to go. (Docs)
Note there are some limitations, for example this won't pick up Identity Column definitions from the source table used in the view.
An example:

Any way to find out the which objects use or populate a particular table in oracle

I have a certain requirement where in I have been given a table name say ABC, i want to find out which all procedures,packages,mv's,functions refer to that particular table 'ABC' or do a insert or update on that table. Is there any way or query to find this.
Since I cannot look up the code of every object in the schema, I am searching for another way.
You may use Oracle System view dba_dependencies (check with your dba if you don't have access to this view).
select *
from dba_dependencies
where referenced_name='ABC'
and referenced_type='TABLE';
Beware, your objects may also use synonyms. So a second list could come with:
select *
from dba_dependencies
where referenced_name='ABC'
and referenced_type='SYNONYM';

Whats the privilege required to access ALL_ARGUMENTS in Oracle?

I want to know which privilege is required to access the table ALL_ARGUMENTS in Oracle? There is any specific one?
Example:
SELECT * FROM ALL_ARGUMENTS
Searched on web but found nothing.
The ALL_ARGUMENTS table is returned when we execute this:
SELECT * FROM sys.dba_tab_privs WHERE grantee='PUBLIC' and table_name like 'ALL_ARGUMENTS'
We see a value of PUBLIC as the grantee. That means, PUBLIC has SELECT privilege.
Reference: https://docs.oracle.com/database/121/TTSYS/systemtables.htm#TTSYS348
There may be other tables in SYS, for which this is not true: Then, ADMIN or SELECT ANY TABLE privileges are needed.
Typically, anyone can see ALL_ARGUMENTS. For that matter, anyone can see any ALL_ data dictionary view.
It will show you YOUR arguments, and any argument for an object you are also able to view based on your privilege level.
This security check is why querying DBA_ views is always (generally) faster than querying ALL_ views - because it just shows EVERY SINGLE ARGUMENT regardless of object privileges.
Not every view has an ALL_ and a DBA_ version.
From the DOCS

How to find all tables updated by a particular plsql method

Is there any way to find all which tables are (potentially) updated by a particular PLSQL method, other than by code inspection?
No, not really.
ALL_DEPENDENCIES lists the tables statically referenced by a PL/SQL package but that will include both tables read and tebles updated, and it's for the entire package, not just a single procedure. Tables updated via dynamic SQL are not listed. Also, a procedure can call procedures outside the package, and they can in turn update additional tables.
Maybe query the all_source table:
select * from all_source
where name = 'procedure_name'
and upper(text) like upper('%update TABLE_NAME%');
While not exactly what you want, it will show what procedures, functions or packages contain the table_name right after an UPDATE (assuming they are on the same line).

Oracle: search though all stored procs/triggers/other db code?

Is it possible to search through all of the programmatic objects (functions, stored procedures, triggers, etc) across multiple schemas in Oracle?
There are a number of tables that appear to be unused in my code, but I don't want to break anything by removing them without checking first.
It is possible to search through object code-- you'd generally use the DBMS_METADATA package to generate the DDL for the object and then search the CLOB. However, it doesn't sound like that's actually what you want to do.
If you are just trying to figure out whether a table is referenced by any code in your system, you would generally want to use the DBA_DEPENDENCIES view (or ALL_DEPENDENCIES or USER_DEPENDENCIES depending on your privileges and the scope of what you're looking for). Something like
SELECT *
FROM dba_dependencies
WHERE referenced_owner = 'SCOTT'
AND referenced_name = 'EMP'
AND referenced_type = 'TABLE'
will show you everything that depends on the EMP table in the SCOTT schema.
The only time you'd want to search code rather than looking at DBA_DEPENDENCIES would be when you had code that was doing dynamic SQL where the table name was hard-coded. But that's relatively unlikely in practice.
You can search the DBA_SOURCE view:
SELECT *
FROM dba_source
WHERE UPPER(text) LIKE '%YOUR_TABLE_NAME%';
Do this in Toad by selecting:
Search => Object Search
If you had Toad you could do this built-in. (I removed my schemas for privacy)

Resources