There is a way to do that by
- enclosing your code into brackets
echo
-ing every line within brackets
- and - if necessary (like in my example) - escaping
<
with 3 ^
signs.
- finally, pipe it to SQL*Plus
Looks kind of stupid, but it works. Here's how.
The p1.bat
script:
@echo off
set /p uname=Enter SQLPlus username:
set /p pwd=Enter SQLPlus password with instance:
(
echo select table_name
echo from user_tables
echo where rownum ^^^<= 5
echo order by table_name;
) | sqlplus %uname%/%pwd%
Testing:
c:\Temp>p1
Enter SQLPlus username:scott
Enter SQLPlus password with instance:tiger
SQL*Plus: Release 11.2.0.2.0 Production on Sri Lis 28 21:45:34 2020
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> 2 3 4
TABLE_NAME
------------------------------
BONUS
DEPT
EMP
LINKS
SALGRADE
SQL> Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
c:\Temp>
In my opinion, a separate .SQL
file is simpler. See if you can avoid that "restriction" you mentioned.