Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to print out the definition of a procedure in Oracle?

Tags:

sql

oracle

plsql

Is there a way in oracle to see what a procedure's structure is? I'm trying to log and am running procedures and wanted to store the actual procedure structure in my log.

like image 446
Nicholas Avatar asked Aug 23 '11 20:08

Nicholas


People also ask

How do you view a procedure definition?

To view the definition a procedure in Object Explorer In Object Explorer, connect to an instance of Database Engine and then expand that instance. Expand Databases, expand the database in which the procedure belongs, and then expand Programmability.

How define procedure in Oracle?

The syntax to create a procedure in Oracle is: CREATE [OR REPLACE] PROCEDURE procedure_name [ (parameter [,parameter]) ] IS [declaration_section] BEGIN executable_section [EXCEPTION exception_section] END [procedure_name]; When you create a procedure or function, you may define parameters.

How do you define a stored procedure in SQL?

A stored procedure is a prepared SQL code that you can save, so the code can be reused over and over again. So if you have an SQL query that you write over and over again, save it as a stored procedure, and then just call it to execute it.


3 Answers

You could query the ALL_SOURCE table

SELECT text 
  FROM all_source
 WHERE owner = <<owner of procedure>>
   AND name  = <<name of procedure>>
 ORDER BY line

If you are dealing with a procedure that is inside a package

SELECT text 
  FROM all_source
 WHERE owner = <<owner of procedure>>
   AND name  = <<name of procedure>>
   AND type  = 'PACKAGE BODY'
 ORDER BY line

will give you the text of the package body. You could also get the text of the package specification using a TYPE of "PACKAGE"

like image 76
Justin Cave Avatar answered Oct 10 '22 07:10

Justin Cave


SELECT TEXT, LINE FROM ALL_SOURCE WHERE 
    NAME = UPPER('$name') -- the table also has an owner field to track the user
    ORDER BY TYPE, -- type is generally procedure, but there are functions and 
                   -- more complex structures as well, such as PACKAGE
    TO_NUMBER( LINE )
like image 41
cwallenpoole Avatar answered Oct 10 '22 08:10

cwallenpoole


dbms_metadata package, get_ddl function, perhaps?

SELECT dbms_metadata.get_ddl('PROCEDURE','<yourproc>','<schema>') FROM dual;
like image 31
DCookie Avatar answered Oct 10 '22 06:10

DCookie