Searching for a specific JOB by the procedure it calls - oracle

Is it possible to search a JOB by the code it executes?
I.E. I want to find the JOB that launches a certain stored procedure.
Is there a query to do it?

select
*
from
user_jobs
where
what like '%my_token%';

Try using the all_dependencies view.
select * from all_dependencies where referenced_name = 'YOUR_STORED_PROC';

Related

Oracle Stored Procedure List Parameters

I'm developing a .NET front end that interacts with an Oracle database. I have figured out how to get a list of stored procedures to execute, but I don't know how to get a list of parameters that belong to the stored procedure. I want to be able to show a list of all the parameters that are both input and output parameters for the stored procedure.
I have tried using the DBA_SOURCE, DBA_PROCEDURES, ALL_DEPENDENCIES, but I haven't seen anything that shows the parameters that belongs to the specified stored procedure.
Any ideas?
I believe that both responses I received are correct, but I ended up finding a different query which gives me exactly what I'm looking for:
SELECT
ARGUMENT_NAME,
PLS_TYPE,
DEFAULT_VALUE
FROM
USER_ARGUMENTS
WHERE
OBJECT_NAME = '<my_stored_proc>'
This has been working for me so far and pulls all the OracleParameter information that I want as well.
You find parameter metadata in DBA/ALL/USER_ARGUMENTS view.
This is the query that we use, more or less:
SELECT *
FROM
ALL_ARGUMENTS
WHERE
DATA_TYPE IS NOT NULL
-- This check removes package procedure arguments that don't really
-- seem to mean anything
AND
DATA_LEVEL = 0
-- Use this predicate to remove entries for the return value of functions
AND
POSITION > 0
ORDER BY
OWNER,
PACKAGE_NAME,
OBJECT_NAME,
OBJECT_ID,
OVERLOAD,
POSITION

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;

How to get information about a User-Defined Type?

In simplicity, PL/SQL generally follow the following:
DECLARE
Variable declaration
BEGIN
Program Execution
EXCEPTION
Exception handling
END;
I am quite new to PL/SQL and i am looking at the variable declaration section where i would like to find out more information on SALES_PRODUCT_TY_LIST.
Is there a table i may look up to check on information on SALES_PRODUCT_TY_LIST, such as checking out table column information from all_tab_cols view?
CREATE OR REPLACE PROCEDURE GET_DISCOUNTS
(
v_have_list SALES_PRODUCT_TY_LIST
)
IS
QUERY VARCHAR(5000);
...
Thanks.
The Oracle database has an extensive data dictionary (what some other DBMS products call the INFORMATION SCHEMA). You can find all the views here. Alas, the revised ToC structure makes it harder to find something in the 11g documentation unless you already know what you're looking for, so use the index instead. 8-)
Anyway, the views you need to query are ALL_TYPES and ALL_TYPE_ATTRS.
This seems to be user defined collection type. You can find some information about it querying all_types/user_types view:
select * from user_types where type_name = 'SALES_PRODUCT_TY_LIST'
The definition of the type can be found for example by querying all_source/user_source view:
select text from user_source where name = 'SALES_PRODUCT_TY_LIST' order by line
Try this to get DDL:
SELECT dbms_log.substr(dbms_metadata.get_ddl('TYPE', 'SALES_PRODUCT_TY_LIST'), 32767,1)
FROM DUAL;
see: http://www.myoracleguide.com/s/gen_schema.htm
Ok i found something:
select *
from all_objects
where object_name like 'SALES%';

How to check if a stored procedure exist?

I have searched the net and I've found a post that uses the following snippet to check if a stored procedure exists:
select *
from USER_SOURCE
where type='PROCEDURE'
and name='my_stored_procedure.'
Is there any other way to check if a procedure exists?
Edited to add:
Before posting SQL Server ways, please I'm looking for ORACLE ways.
Alternatives:
USER_PROCEDURES:
SELECT *
FROM USER_PROCEDURES
WHERE object_name = 'MY_STORED_PROCEDURE'
USER_OBJECTS:
SELECT *
FROM USER_OBJECTS
WHERE object_type = 'PROCEDURE'
AND object_name = 'MY_STORED_PROCEDURE'
Something that worked for me!
SELECT text
FROM all_source
WHERE name = 'MY_SP_NAME'
ORDER BY line;
Alternatively you can try calling SP like this:
CALL MY_SP_NAME();
You might end up error like this, but that confirms you have SP defined there:
OCI Statement Execution failure.ORA-06553: PLS-306: wrong number or types of arguments in call to 'MY_SP_NAME'
The only way to see if a procedure exists in the database is though querying DBA_OBJECTS. The disadvantage here is that only a dba has access to this view. Second best is using all_objects. ALL_OBJECTS shows you the objects for which you have somehow a privilege. USER_OBJECTS only shows you your own objects.
Execute the query below in SQL*PLUS, ODBC Test,...
SELECT text FROM all_source WHERE name='MY_PROCEDURE' ORDER BY line
where MY_PROCEDURE is the stored procedure name.
Below is sample output:
Get Data All:
"TEXT"
"PROCEDURE Usp_Get_Blob
"(
"P_DOC_ID INT,
"P_DOC_TEXT OUT BLOB)
"as
"begin
" select B1
into p_doc_text
" from blobtest
" where ID = p_doc_id;
"end; "
I was not able to find stored procedure with any of the methods above.
Reason: stored procedure was inside package. Oracle uses packages to gather several stored procedures in one module.
This will display the stored procedure and its contents stored in the table.
select
name c1,
text c2
from
dba_source
where
name = upper('procedure_name')
order by
line asc;
select *
from USER_SOURCE
where type='PROCEDURE'
and name='my_stored_procedure.'

How can I get all the triggers linked to a specific table?

I'm searching for a way to retrieve all the triggers where there is an action linked to a specific table.
I don't want to read manually all the triggers I have on the server as there are too many.
Any ideas?
SELECT * FROM USER_TRIGGERS WHERE TABLE_NAME = 'NAME_OF_YOUR_TABLE';
If you mean what Peter Lang indicated then look into the view dba_dependencies (or all_dependencies or user_dependencies of course).

Resources