Find stored proc's dependent elements in Oracle - oracle

I have add a parameter to an existing oracle stored proc. Is there a simple way to find other stored proc that would have to be modified?
I'm using Oracle SQL Developper.

You can query DBA_DEPENDENCIES (or ALL_DEPENDENCIES or USER_DEPENDENCIES) directly to get that information
SELECT owner,
name,
type
FROM all_dependencies
WHERE referenced_owner = <<owner of procedure>>
AND referenced_name = <<name of procedure>>
In SQL Developer, you can also pull up the procedure and click the "References" tab to get a list of the objects that reference the procedure.

Related

List all procedures along with the tables and columns used in that procedure in Oracle

Last night got a call from my team lead and he asked me to make the list of all the procedures along with the tables and columns used in Oracle.
I got a query to list all the procedures along with tables and dblink but couldn't get column names (along with DML if possible) used in that Procedure :
select DISTINCT OWNER, NAME, referenced_name, referenced_link_name, referenced_type
from dba_dependencies
where OWNER = 'OWNER_NAME';
My required output is as follows:
Owner_Name
Procedure_Name
Referenced_name
Referenced_link
Referenced_type
Column_Name,
dml_type(select/insert/update).
Please help if possible..
columns will be in DBA_TAB_COLUMNS.
as for the SQL statements, this is a bit more difficult, but doable if you have Diagnostics pack licensed; here's the outline (works in 11g or above):
DBA_HIST_ACTIVE_SESS_HISTORY.top_level_sql_id is the SQL id of the calling procedure,
so listing DBA_HIST_ACTIVE_SESS_HISTORY.sql_id for that top_level_sql_id is "all" the SQL from the execution of the procedure.
DBA_HIST_SQL_TEXT can be queried to get the sql text for the sql_id.
If you don't have the Diagnostics Pack, you'd have to instrument v$session for the top_level_sql_id's and sql_id's and the look in v$sql for the text.

How to get parameters properties from a stored procedure in Oracle?

I am developing an admin panel where we can determine which stored procedures and views can be called in Oracle 12c schemas, from services in our micro-services platform.
The services must know which parameters a procedure needs, and which columns a view has available, in order to call them.
I the admin panel, the creator of the procedure or view may register it, by typing in these information, like object's name, each parameter's name, length and data type.
But it would be much more elegant if the user just types the name of the object and then a SQL SELECT would retrieve a procedure's parameters properties in a table, and the same with the view's column's properties, so the panel would register those configurations automatically.
Could anybody post a query on how to achieve this? I am very new to Oracle and I don't know how to query the objects metadata.
I believe your are looking for something like this.
SELECT *
FROM SYS.DBA_PROCEDURES
WHERE OBJECT_TYPE = 'PROCEDURE'
AND OBJECT_NAME = 'xxxx'
Once you have that, you can get the parameters from something like this.
SELECT *
FROM SYS.ALL_ARGUMENTS
where object_name = 'procedure_name';
This can be used for views (I used USER_... metadata views, but you can use DBA_... depending of user grants):
SELECT A.TABLE_NAME, A.COLUMN_NAME, A.DATA_TYPE
FROM USER_TAB_COLUMNS A
INNER JOIN USER_VIEWS B ON A.TABLE_NAME = B.VIEW_NAME
/* WHERE A.TABLE_NAME = 'xxxx' */
ORDER BY TABLE_NAME, COLUMN_ID;

How to identify all stored procedures refering a particular table in Oracle

I am working with Oracle 12c and need to find all references where a specific table or view is being used in Stored Procedure/Function and packages.
I have found a this answer about MS SQL Server, but it's not related to Oracle, besides sp_help and sp_depends sometimes return inaccurate results.
I know to search in column text of table all_source, for example, this code (search only standard user defined package names, not system package):
SELECT type, name, line, text
FROM all_source
WHERE type = 'PACKAGE BODY'
AND name like 'P%'
AND UPPER(text) like '%' || p_table_or_view_name || '%'
ORDER BY name, line;
but I'm looking if there's a more elegant and/or standard solution in Oracle.
I'm also checking if this answer can help me in any way.
I will appreciate any assistance.
Use the ALL_DEPENDENCIES dictionary table:
SELECT *
FROM ALL_DEPENDENCIES
WHERE referenced_name = 'YOUR_TABLE_NAME'
AND owner = 'YOUR_USER';

to check any procedure or trigger written ove table

I want to check in Oracle that if is there any Procedure or trigger written on the database table which insert the records in the table.
Please help me to find out this because I have an existing table and want to check that in that table how records would be insert.
Thanks in advance!
Dependencies between objects are maintained in the system and can be read from DBA_DEPENDENCIES (or ALL_ or USER_DEPENDENCIES).
The only limitation is that dynamic statements (eg using execute immediate) are not included because they are not known at compile time.
Please use the below code snippet. Hope this helps!
SELECT *
FROM
(SELECT owner,
name,
type,
referenced_owner,
referenced_name,
referenced_type,
owner sdev_link_owner,
name sdev_link_name,
type sdev_link_type
FROM ALL_DEPENDENCIES
WHERE REFERENCED_OWNER = 'OBJECT_OWNER'
AND referenced_name = 'TABLE_NAME'
) sub1
ORDER BY 3 ASC;

Obtain stored procedure metadata for a procedure within an Oracle package using ADO.NET

I am trying to obtain the stored procedure metadata (procedure name,parameter types,parameter names etc) for a procedure declared within an Oracle package, using the standard ADO.NET API - DbConnection.GetSchema call. I am using the ODP driver.
I see that the Package is listed in the 'Packages' and 'PackageBodies' metadata collections. The procedure parameter appears in the 'Arguments' and 'ProcedureParameters' collections. I do not see a way to get to the procedure information via the package metadata. Even if the procedure does not have any parameters there is a row in the 'ProcedureParameters' collection for this procedure.
My question: To obtain the procedure metadata do I have to query the 'ProcedureParameters' collection and search for an entry with the required package name? I can then construct the procedure metadata based on the parameter information. Is there a shorter or quicker way to obtain the same information?
I'm not sure how you'd get this using ADO.NET, but you can directly query the database to get this information as follows:
SELECT *
FROM SYS.DBA_PROCEDURES
WHERE OBJECT_TYPE = 'PACKAGE' AND
OBJECT_NAME = '<your package name here>' AND
PROCEDURE_NAME IS NOT NULL;
Once you've run the above query you'll have a result set which has, among other things, the PROCEDURE_NAME. Given the package name and the PROCEDURE_NAME, you can find parameter info using the following query:
SELECT *
FROM SYS.ALL_ARGUMENTS
WHERE PACKAGE_NAME = '<your package name here>' AND
OBJECT_NAME = '<PROCEDURE_NAME from query above>';
Share and enjoy.
With help from Bob I've used the following query to obtain a list of stored procedures defined within a package.
SELECT a.OBJECT_NAME,p.PROCEDURE_NAME FROM SYS.ALL_OBJECTS a, SYS.ALL_PROCEDURES p WHERE a.OBJECT_NAME = p.OBJECT_NAME AND a.OBJECT_TYPE = 'PACKAGE' AND a.OWNER = '" + ownerName + "' AND p.PROCEDURE_NAME IS NOT NULL"
This returns all stored procedures for a particular user. I can then use the 'ProcedureParameters' collection to obtain the parameter information for them.
NOTE: Do not query the SYS.DBA_PROCEDURES table. The user credentials you use to execute the query might not have 'select' privileges on that table.

Resources