Oracle
  Home arrow Oracle arrow Reading Text Files using Oracle PL/SQL...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Developerworks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ORACLE

Reading Text Files using Oracle PL/SQL and UTL_FILE
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 63
    2006-04-11

    Table of Contents:
  • Reading Text Files using Oracle PL/SQL and UTL_FILE
  • How to read a text file from a file system and display the contents using PL/SQL
  • How to read a text file from a file system and display the contents using PL/SQL: discussion
  • Improving it a bit with exception handling

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    Reading Text Files using Oracle PL/SQL and UTL_FILE
    (Page 1 of 4 )

    In this series of articles, we shall concentrate on working with file input/output using Oracle PL/SQL packages. Even though I start with simple examples in the first article of this series, I shall introduce you (in my upcoming articles) to the power of the most advanced techniques using file input/output with Oracle PL/SQL.

    This will be an add-on to my long PL/SQL series on this website.  If you are new to PL/SQL, I strongly suggest you go through my huge "Database interaction with PL/SQL" series.

    All the examples in this article have been tested only with Oracle 10g version 2 on Windows Server 2003 standard edition.  I didn't really test the examples on any of the previous Oracle versions.  The examples will be a bit different when you work with non-Windows environments.  I suggest you refer to your DBA or manuals for the specific platform on which you are going to work.

    I am confident enough that all of the examples should give no problem when worked with Oracle version 7.3 or above (on Windows).  You can drop (or post) me a line if any of them do give you problems.  The examples can be directly copied, pasted and tested in your favorite PL/SQL environment.  They should work without any changes.

    What is necessary to work with a file system using Oracle PL/SQL

    Reading files from a host operating system is allowed only from Oracle 7.3 or above.  To accomplish tasks related to reading and writing files to the host operating system, Oracle includes a pre-defined package called "UTL_FILE."

    "UTL_FILE" allows PL/SQL programs to both read and write to any operating system files that are accessible from the server on which your database instance is running.  This package gets automatically installed when you install Oracle database on your system. 

    What do we need to do before working with "UTL_FILE"?  Earlier, we need to work with an entry "UTL_FILE_DIR" in "init.ora" file which resides in the Oracle installed folder.  That entry needs to be added to the "init.ora" with the directory you will use to access the files.  An example would be as follows:

    utl_file_dir = c:sampledata

    The above statement makes Oracle use "c:sampledata" for reading and writing operating system files.  Once you make any change to "init.ora", you may need to restart your database server (unless you use SPFILE).

    If you want to give the permission to any folder on your host operating system, you need to modify the line something like below line:

    utl_file_dir = *

    Please be aware that the above line would be a very huge security risk on production servers.  It suits well only for development purposes.

    There exists one more method which is quite safe and easy.  Oracle highly recommends that you work with the "CREATE DIRECTORY" method rather than using the previous method.  Another advantage to using this method is that it is dynamic (you need not restart your server at all).  So, in this article, I shall proceed with the "CREATE DIRECTORY" method.

    The next section gives you a demo.

    More Oracle Articles
    More By Jagadish Chatarji


       · Hello guys. Starting a small series to work with text files using PL/SQL. Enjoy...
     

       

    ORACLE ARTICLES

    - Tuning PL/SQL Code
    - Debugging PL/SQL Code
    - Testing PL/SQL Code
    - Working With PL/SQL Code
    - Conditional Compilation for Oracle Database ...
    - Compile-Time Warnings for Oracle DB 10g
    - Compiling PL/SQL Code for an Oracle Database
    - Troubleshooting PL/SQL Code
    - Managing PL/SQL Code
    - Data Manipulation and More for HTML DB Appli...
    - Oracle Database Fundamentals
    - Adding Processes to HTML DB Applications
    - Adding Computations, Processes, and Validati...
    - Sub-templates and More with Oracle HTML DB
    - Focusing on Templates in Oracle HTML DB




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway