Oracle
  Home arrow Oracle arrow Page 5 - Writing to Text Files in 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

Writing to Text Files in Oracle PL/SQL
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 61
    2006-04-18

    Table of Contents:
  • Writing to Text Files in Oracle PL/SQL
  • How to count the number of lines from the text file
  • How to copy the information from a text file into a table using PL/SQL
  • How to write into a text file from PL/SQL
  • How to copy from a table into the text file from PL/SQL
  • Other ways to write the information into a text file from PL/SQL

  • 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

    PCmover - $15 Off with Coupon Code CJPH7Q

    Writing to Text Files in Oracle PL/SQL - How to copy from a table into the text file from PL/SQL
    (Page 5 of 6 )

    We have already seen how to write to files from the previous section.  Now, we shall see how to copy information from a table into the text file. 

    Let us go through the following code first:

    declare
        f utl_file.file_type;
    begin
        f := utl_file.fopen('SAMPLEDATA','sample2.txt','W');
        for s in (select remarks from sampletable)
        loop
            utl_file.put_line(f,s.remarks);
        end loop;
        utl_file.fclose(f);
    end;

    For the above code, I am using the same table defined in the previous sections.  Let us go through the most important bits of the above program.

    for s in (select remarks from sampletable)

    The above statement goes through every row in the table “sampletable” and retrieves the value of the column “remarks” and places it in the variable “s.”  The variable “s” would contain a new value for every iteration of the “for” loop.  Further proceeding, we have the following:

    utl_file.put_line(f,s.remarks);

    The above statement is a bit different from any of the previous ones.  You must consider that “s” is no longer a simple “varchar2” variable.  It is being managed by PL/SQL automatically.  And “s” alone cannot maintain a single value.  In fact, it maintains a RECORD type of value.  That means the variable “s” may contain more than one column based on the SELECT statement we provide.  And thus to retrieve any value from “s,” we need to specify the column value also along with the variable “s.”

    More Oracle Articles
    More By Jagadish Chatarji


       · Hello guys. You can work with text files very easily from within Oracle PL/SQL. ...
       · Hi,I have a problem regarding writing to text files.I am using spooling now and...
     

       

    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

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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