Warning

 

Close
Confirm Action

Are you sure you wish to do this?

Cancel Confirm
AR15.COM
8/19/2015 8:31:11 AM EDT
I'm trying to figure out how to write a windows batch script that uses the sqlplus command line to connect to a database, run a query, and return the results to a tab delimited .txt file on my local drive.

I've found a bunch of articles google searching on how to do this, but none seem to work.

I want to store the query to be run inside a file query.sql, then be able to run something like this within a windows batch file:

sqlplus username/password@oracledatabase @"%~dp0\query.sql"

to call sqlplus, run the query, and dump the result to a text file.

I need to do this in a batch file because I'm going to string it together with some other commands that will work with the resulting output file: feeding it into another comand line program, taking the output from that program and loading it back into the oracle database using sqlldr.

Has anyone done something like this? Any suggestions?


8/19/2015 8:32:39 AM EDT
[#1]
perl
8/19/2015 8:40:32 AM EDT
[#2]
This should work... worked for me
8/19/2015 8:45:07 AM EDT
[#3]
I've done something like that, but only to create tables/insert into tables.  Never tried to export to .txt




Is it failing from the very beginning?


 
8/19/2015 9:10:24 AM EDT
[#4]
This is the method I'm trying:

http://mycodeblog.blogspot.com/2006/12/sql-plus-delimited-output-file.html