Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLPLUS command line with Windows batch file

I want to create a batch file which will open the SQLPLUS [CLI] and will execute some stored sql file and will also store the output to text file.

So I've created this batch file [which does not work].
These SQL file contains SQL which returns the max number from a table.

sqlplus scott/tiger@DB
@sql1.sql>data1.txt
@sql2.sql>data2.txt

The problem is it does not executes the SQL files after opening the SQLPLUS

  • Windows XP
  • Oracle 9i
like image 200
Sourav Avatar asked May 07 '13 05:05

Sourav


2 Answers

What about native Sql*plus spooling?

run.bat:

sqlplus hr/hr@sandbox @d:\run.sql

run.sql:

spool d:\run.log
set echo on 

select * from dual
/
exit

run.log:

01:50:20 HR@sandbox> 
01:50:20 HR@sandbox> select * from dual
01:50:20   2  /

D
-
X

Elapsed: 00:00:00.00
01:50:21 HR@sandbox> exit
like image 183
Kirill Leontev Avatar answered Oct 21 '22 09:10

Kirill Leontev


SET ORACLE_SID=<YOUR SID HERE>

sqlplus scott/tiger@DB < sql1.sql > data1.txt
sqlplus scott/tiger@DB < sql2.sql > data2.txt
like image 35
valex Avatar answered Oct 21 '22 08:10

valex