Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

output of Select statement to a file

output of Select statement to a file

output of Select statement to a file

Is there anyway to send the SELECT statement ouput to a file, e.g. myresult.rpt?
like select * from table > 'C:\table.rpt' or
select * from table; output to 'C:\table.rpt'

I need to send the output to a file that I download from the web later or diaplay it on the web page.

The later command above (output to) fails when I execute it from inside my ASP page. Even spool is also an Oracle command.

My backend database is Oracle, but as I am using only SQL, so i need a SQL command. Thus, "Spool table.rpt; select * from table" also fails.

any kind of help will be appreciated
Thanks in advance

RE: output of Select statement to a file

If you are using SQL, you could probably use PL/SQL just as easily.

If you use PL/SQL, you can use your select statement to populate a cursor, then go through the cursor and write out the results using the UTL_FILE package.  You can also write out your HTML tags at the same time to generate web-ready pages.

RE: output of Select statement to a file

Hi Nanda,

it's a good idea to use the UTL_File package (see http://www.orafaq.com/faqplsql.htm). Here are some lines of code, taken from that page and slightly modified:

  fileHandler UTL_FILE.FILE_TYPE;
  h_var VARCHAR2(20);
  fileHandler := UTL_FILE.FOPEN('/tmp', 'myfile.txt', 'w');
-- retrieve data from a table...
  select something into h_var from sometable;
-- now write the retrieved data to the file...
  UTL_FILE.PUTF(fileHandler, h_var);
  WHEN utl_file.invalid_path THEN
     raise_application_error(-20000, 'ERROR: Invalid path for file or path not in INIT.ORA.');

Hope this helps,

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close