to check any procedure or trigger written ove table - oracle

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;

Related

How can I find the invisible table in oracle 11g?

There is a table named IM_RESULT_INFO. Because I can see it by SELECT * FROM IM_RESULT_INFO.
But it doesn't exist in table nor view lists in sqldeveloper. I also tested SELECT * FROM all_all_tables and SELECT * FROM dba_tables, and couldn't find the table.
In Eclipse IDE, I searched for it in whole project files, but the only code I found was SELECT ... FROM IM_RESULT_INFO.
I think it is a mixture of tables, but there's no way to analyze it. How can I find it?
It must be a synonym or a view, check the synonyms view to see what object is referenced by it:
SELECT *
FROM all_synonyms
WHERE synonym_name = 'IM_RESULT_INFO'
Or the views view:
SELECT *
FROM all_views
WHERE view_name = 'IM_RESULT_INFO'
You can check in ALL_OBJECTS if you are not sure about the type of an object. It will provide you the Types and other important details also.
For Materialized view please check ALL_MVIEWS.
SELECT *
FROM ALL_OBJECTS
WHERE OBJECT_NAME='IM_RESULT_INFO';

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.'

Oracle--Error(Refereence to object_id)

SELECT object_id from dbname.tablename
This query has to be executed against oracle 11g.I get errors when i execute this.
I do a migration from sybase to oracle and in oracle this query fails.
What could be the problem. Please suggest a solution
"What could be the problem."
All sorts of things. Since you failed to state what errors you're getting, we can only guess, e.g.:
Table not found
No SELECT privilege on table
dbname not a valid schema
object_id not a column in the table
Not connected to a running oracle instance
Trying to run the statement in an environment that doesn't understand SQL
etc, etc, ...
If all you want is to check that the table exists, you could do this:
SELECT 1 FROM dba_tables WHERE owner = 'DBNAME' AND table_name = 'TABLENAME';
If you want to check that you can query the table, you could do this:
SELECT 1 FROM schemaname.tablename WHERE 1=0;
If you want to check if the table has any rows, you could do this:
SELECT 1 FROM schemaname.tablename WHERE ROWNUM <= 1;
What you will do with the result. If you only want a unique id for a row, yo can user SELECT ROWID FROM dbname.tablename!

Passing SQL to an Oracle bind variable

I need to execute something like:
select
[very big SQL]
where phone_number in(:SQL2)
Is it possible to use bind variable for SQL2?
I want to save the execution plan of the major SQL.
Thanks.
Create a temporary table and save SQL2's results there prior to executing SQL1:
CREATE GLOBAL TEMPORARY TABLE mytemptable (id INT NOT NULL)
CREATE OUTLINE ol_sql1
ON
SELECT *
FROM sql1
WHERE id IN
(
SELECT id
FROM mytemptable
)
INSERT
INTO mytemptable
SELECT *
FROM sql2
SELECT *
FROM sql1
WHERE id IN
(
SELECT id
FROM mytemptable
)
If this query gets executed a lot of times, I wouldn't use a temporary table for it.
There is a 'trick' to bind an inlist, which Tom Kyte describes on his blog:
http://tkyte.blogspot.com/2006/06/varying-in-lists.html
I would bet on that being much more efficient. It should be easy to prove with a SQL Trace.
Further to Quassanoi's point. It sounds like you may not be familiar with temporary tables. This is a good introduction.
You only create the table once. Then within a given session you first:
populate the temporary table
execute your query pulling from the temporary table
rollback.
There's no risk of conflicting/overlapping with another session's data.

Resources