BC remote Oracle DBA - Call (800) 766-1884  
Oracle Consulting Oracle Training Development

Remote DBA

Remote DBA Plans  

Remote DBA Service

Remote DBA RAC

Remote DBA Oracle Home
Remote DBA Oracle Training
Remote DBA SQL Tuning Consulting
Remote DBA Oracle Tuning Consulting
Remote DBA Data Warehouse Consulting
Remote DBA Oracle Project Management
Remote DBA Oracle Security Assessment
Remote DBA Unix Consulting
Burleson Books
Burleson Articles
Burleson Web Courses
Burleson Qualifications
Oracle Links
Remote DBA Oracle Monitoring
Remote DBA Support Benefits
Remote DBA Plans & Prices
Our Automation Strategy
What We Monitor
Oracle Apps Support
Print Our Brochure
Contact Us (e-mail)
Oracle Job Opportunities
Oracle Consulting Prices





Remote DBA services

Remote DBA Support

Remote DBA RAC

Remote DBA Reasons

Remote Oracle Tuning

Remote DBA Links

Oracle DBA Support

Oracle DBA Forum

Oracle Disaster

Oracle Training

Oracle Tuning

Oracle Training

 Remote DBA SQL Server

Remote MSSQL Consulting

Oracle DBA Hosting

Oracle License Negotiation







  Oracle Tips by Burleson

Retrieving the Source from the Database

The developers have created a set of procedures and functions and loaded them into the database.  Sometimes you need to be able to pull the source code back out of the database.  When a named block is sent to the database its source is loaded into the database and then compiled.  The source is maintained in a view called user_source .  To pull the source code out of the database, first list the objects in the database belonging to the user. 

SQL> select
  2    object_name,
  3    object_type,
  4    status
  5  from user_objects;

OBJECT_NAME                    OBJECT_TYPE        STATUS
------------------------------ ------------------ ------
AUTHOR                         TABLE              VALID
BOOK                           TABLE              VALID
BOOK_AUTHOR                    TABLE              VALID
CALC_AREA                      FUNCTION           VALID
EMP                            TABLE              VALID
F2C                            FUNCTION           VALID
FULL_NAME                      FUNCTION           VALID
GET_AREA                       PROCEDURE          VALID
GET_AREA2                      PROCEDURE          VALID
JOB                            TABLE              VALID
MK_MONEY                       FUNCTION           VALID
NUM2WORD                       FUNCTION           VALID
NUM_CHECK                      PROCEDURE          VALID
PUBLISHER                      TABLE              VALID
SALES                          TABLE              VALID
STORE                          TABLE              VALID
VALID_NUMB                     FUNCTION           VALID

17 rows selected.

To find the code for the function num2word we look at user_source.

SQL> desc user_source;

 Name                         Type
 ---------------------------- --------------
 NAME                         VARCHAR2(30)
 TYPE                         VARCHAR2(12)
 LINE                         NUMBER
 TEXT                         VARCHAR2(4000)
The user_source  view contains a row for each line of source code.  To retrieve the code for the num2word function, select the text for that function.

SQL> select text
  2  from user_source
  3  where name = 'NUM2WORD'
  4  order by line; 

function num2word
  (n_number IN number)
  return varchar2
  if n_number = 1
    then return 'one';
  elsif n_number = 2 then return 'two';
  elsif n_number = 3 then return 'three';
  end if;

11 rows selected.

The code is listed in the format that it was submitted to the database.  To find out which objects have source listed in user_source, select the object name.

SQL> select distinct name from user_source; 


9 rows selected.

The query must use the DISTINCT clause  as there is a row for each line of source code defining each object.  Since each line of source code is in a separate row in the view, you need to order the row by line or the lines could be returned out of order.

At this point, we have covered three of the four PL/SQL blocks; anonymous blocks , procedures and functions.  The forth block, the trigger  will be covered in Chapter 5 Bulk Operations, Packages and Triggers.  Before continuing on to using PL/SQL to interact with the database, we need to cover PL/SQL’s error handling capabilities. So what happens when PL/SQL runs into an error?  If the error is caught during compilation, the PL/SQL compiler returns the error to the submitting application, such as SQL*Plus.  If the code is already compiled and is executing in the database, the PL/SQL engine will raise an exception. 

The above book excerpt is from:

Easy Oracle PL/SQL Programming

Get Started Fast with Working PL/SQL Code Examples

ISBN 0-9759135-7-3   

John Garmany 


Remote DBA Service

Oracle Tuning Book


Advance SQL Tuning Book 

BC Oracle support

Oracle books by Rampant

Oracle monitoring software







BC Remote Oracle Support

Remote DBA

Remote DBA Services

Copyright © 1996 -  2013 by Burleson. All rights reserved.

Oracle® is the registered trademark of Oracle Corporation.