How to print definition of a procedure in a package - oracle

I use the below query to get the definition of a stored procedure.
SELECT text
FROM all_source
WHERE owner = <<owner of procedure>>
AND name = <<name of procedure>>
AND type = 'PROCEDURE'
ORDER BY line
I execute the below query which will print the definition of the complete package . The name column in all_source table is updated with package name for the complete package source. Is there a way to get only the procedure source inside a package?
SELECT text
FROM all_source
WHERE owner = <<owner of procedure>>
AND type = 'PACKAGE BODY'
ORDER BY line

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

LAST_DDL_TIME Not Changing after create or replace package body again

On Nov 24 th, we created the package body. Again today we created (create or replace) the same package body object, but last DDL date has not changed. Is there any reason for this ?
Below is the query I'm using
SELECT object_name, object_type, created, last_ddl_time, status FROM ALL_OBJECTS WHERE OBJECT_NAME = 'xxxxxxxxx';
Your query could be wrong.
You need to add this to your WHERE clause:
AND OBJECT_TYPE = 'PACKAGE BODY'
Your query would bring back the SPEC as well as the BODY and only the BODY was updated...theoretically since you're not saying exactly HOW you updated your package.

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.

how to find source search for a table?

i have a existing table called property i alter a column called overbook_percent (i change a number 2 to 3) but i want to do a source search to make sure that there is not a variable declaration that sets this to just 2 digits. how would i go about this?not sure you called this a source search.
how can i see where this table column is use?
i tried this but get no output
select text
from dba_source
where upper(text) like 'OVERBOOK_MAX'
;
I'm working on toad for oracle
may be you are looking for this:-
select owner, table_name from all_tab_columns where column_name = 'OVERBOOK_MAX';
This will search all tables with a column name OVERBOOK_MAX
For checking in stored procedures you may try this:-
SELECT DISTINCT type, name
FROM dba_source
WHERE owner = 'OWNER'
AND UPPER(text) LIKE '%OVERBOOK_MAX%';
EDIT
to search a string try this:-
SELECT owner, name, type, line, text
FROM dba_source
WHERE instr(UPPER(text), UPPER(:search_string)) > 0;

How to View Oracle Stored Procedure using SQLPlus?

How can I view the code of a stored procedure using sqlplus for Oracle 10g?
When I type in:
desc daily_update;
it shows me the parameter, but when I try to do the following:
select * from all_source where name = 'daily_update';
I get
no rows selected
What am I doing wrong?
check your casing, the name is typically stored in upper case
SELECT *
FROM all_source
WHERE name = 'DAILY_UPDATE'
ORDER BY TYPE, LINE;

Resources