Monday, January 19, 2009

User_source view for source code

How to view source code of a Function ?
How to view source code of a Prodcedure ?
How to view source code of a Package ?
How to view source code of a Trigger ?

you can view the source code of a function or a procedure by using data dictionary views. All the PL SQL objects like types, procedure, functions, Packages code can be viewed from a view called “USER_SOURCE“.

User_source data dictionary view provides the source code of all the PL SQL objects.
Each line of code represents a single row in this dictionary view.
If you want to view the source of PL SQL OBJECTS created by you then use dictionary view “USER_SOURCE“.

If you want to view the source of PL SQL OBJECTS created by others(other users) but have an execute permisssion on the OBJECTS, then use dictionary view “ALL_SOURCE“.

IF you have ‘SELECT ANY DICTIONARY’ Previliege, then you can view the source of all the pl/sql objects from the dictionary view DBA_SOURCE.

want to view the code of a FUNCTION in oracle ?

select * from user_source where type='FUNCTION' AND NAME='FUNCTION_NAME' ORDER BY LINE;

want to view the code of a PROCEDURE in oracle ?

select * from USER_SOURCE where type='PROCEDURE' AND NAME='PROCEDURE_NAME' ORDER BY LINE;

want to view the code of a PACKAGE SPECIFICATION in oracle ?

select * from USER_SOURCE where type='PACKAGE' AND NAME='PACKAGE_NAME' ORDER BY LINE;

want to view the code of a PACKAGE BODY in oracle ?

select * from USER_SOURCE where type='PACKAGE BODY' AND NAME='PACKAGE_NAME' ORDER BY LINE;

want to view the code of a TRIGGER in oracle ?

select * from USER_SOURCE where type='TRIGGER' AND NAME='TRIGGER_NAME' ORDER BY LINE;

want to view source code of a procedure created by another user?

select * from user_source where type='PROCEDURE' and NAME='PROCEDURE_NAME' and owner='USERS_NAME' order by line;

want to view the source code of a Function created by another user in oracle ?

select * from user_source where type='FUNCTION' AND OWNER='USERS_NAME' AND NAME='FUNCTION_NAME' ORDER BY LINE;

No comments: