SQLPLUS command line with Windows batch file

I want to create a batch file that will open SQLPLUS [CLI] and execute some saved sql file, and also save the output to a text file.

So, I created this batch file [which does not work].
This SQL file contains SQL that returns the maximum number from the table.

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

The problem is that it does not execute SQL files after opening SQLPLUS

  • Windows XP
  • Oracle 9i
+6
source share
3 answers

What about the built-in Sql * plus buffer?

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 
+9
source
 SET ORACLE_SID=<YOUR SID HERE> sqlplus scott/ tiger@DB < sql1.sql > data1.txt sqlplus scott/ tiger@DB < sql2.sql > data2.txt 
+2
source

For your information and for the rest of the community, I used this command line in the dos file:

 sqlplus.exe SIEBEL/ mypass@mydb @D:\App\Siebel\EIM\sql\my_sql_command.sql 

and output:

 SQL*Plus: Release 11.2.0.1.0 Production on Mar. Sept. 13 11:53:52 2016 Copyright (c) 1982, 2010, Oracle. All rights reserved. ERROR: ORA-12154: TNS : ..... 

in fact, I had a command line error ....

 sqlplus.exe SIEBEL/ mypass@mydb **%** @D:\App\Siebel\EIM\sql\my_sql_command.sql 
+1
source

Source: https://habr.com/ru/post/944413/


All Articles