Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

output of Select statement to a flat file 1

Status
Not open for further replies.

Nanda

Programmer
Nov 14, 2000
104
US
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.

My backend database is Oracle, but as I am using only SQL, so i need a SQL command.

any kind of help will be appreciated
Thanks in advance
 
If your backend database is Oracle you will have to use the appropriate Oracle command. Probably you should repost this question in the Oracle forum.

One way of writing output to a flat file is with the UTL_FILE package. In rough outline you would open a cursor to select the data you wish to write, then call utl_file.fopen to open the flat file, loop through the cursor, fetching rows and using utl_file.put_line to write to the file, and finally using utl_file.fclose to close the file.

I hope this helps. The experts in the Oracle forum may have additional suggestions. [sig][/sig]
 
If you are using Oracle SQL then you can simply use the Spool command in your query

i.e

Spool 'c:\mysql\sql1.txt'

Select * from my_table

Spool off

 
If you're using MS SQL, you can do this:

exec master..xp_cmdshell 'isql /q "Select * from MyDatabase..MyTable" -n >> C:\MyTable.txt'

Andel
andel@barroga.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top