0

I'm using a to run with an .sql script:

@ECHO OFF
SET /p usr=username: 
SET /p pwd=password: 
SET /p dbname=dbname: 
set /p tablename=tablename:

sqlplus %usr%/%pwd%@%dbname%.sql

select * from table where (something);
select (something) from table where (something);
exit;

The .bat file and .sql script needs to be in a single file, so I can't call an .sql file. Any ideas? (I'm using Windows 7 if that helps).

Compo
  • 36,585
  • 5
  • 27
  • 39
MarkLee
  • 13
  • 3

1 Answers1

0

Just an idea, but why not create the sql file from your bat file, write the sql commands to it, then execute it. When it's finished you can then delete the sql file.

@ECHO OFF
SET /p usr=username: 
SET /p pwd=password: 
SET /p dbname=dbname: 
set /p tablename=tablename:

SET "sql1=select * from table where ^(something^)^;"
SET "sql2=select ^(something^) from table where ^(something^)^;"
SET "sql3=^(SELECT 1 + LEVEL-1 idx FROM dual CONNECT BY LEVEL ^<^= 10^)^;"

@echo %sql1% > temp.sql
@echo %sql2% >> temp.sql
@echo %sql3% >> temp.sql

sqlplus %usr%/%pwd% @temp.sql

code updated to allow for special characters which need to be escaped, use ^ to escape special characters.

You might also want to look at this answer

Hope all goes well.

SteveP
  • 385
  • 2
  • 11
  • Yea but If I do something like this echo (SELECT 1 + LEVEL-1 idx FROM dual CONNECT BY LEVEL <= 10) > temp.sql It will say file not specified. – MarkLee Mar 01 '19 at 02:57
  • Hi Mark, I've updated my answer to allow for special characters. – SteveP Mar 01 '19 at 08:12