Я думаю, что проблема в пространстве в net_service_name."-S"
- тихий режим для sqlplus.Для диагностики удалите этот ключ и добавьте rem @echo off
.
Например 1. Пробел в net_service_name.
rem @echo off
set user_name=scott
set password=tiger
set net_service_name= esmd
echo exit | sqlplus -s %user_name%/%password%@%net_service_name% @C:\upwork\stackoverflow\bat_sql\sqltest.sql
pause
output:
C:\upwork\stackoverflow\bat_sql>echo exit | sqlplus -s scott/tiger@ esmd @C:\upwork\stackoverflow\bat_sql\sqltest.sql
Usage: SQLPLUS [ [<option>] [<logon>] [<start>] ]
where <option> ::= -H | -V | [ [-L] [-M <o>] [-R <n>] [-S] ]
<logon> ::= <username>[/<password>][@<connect_string>] | / | /NOLOG
<start> ::= @<URI>|<filename>[.<ext>] [<parameter> ...]
"-H" displays the SQL*Plus version banner and usage syntax
"-V" displays the SQL*Plus version banner
"-L" attempts log on just once
"-M <o>" uses HTML markup options <o>
"-R <n>" uses restricted mode <n>
"-S" uses silent mode
C:\upwork\stackoverflow\bat_sql>pause
Например 2.
rem @echo off
set user_name=scott
set password=tiger
set net_service_name=esmd
echo exit | sqlplus -s %user_name%/%password%@%net_service_name% @C:\upwork\stackoverflow\bat_sql\sqltest.sql
pause
выход:
C:\upwork\stackoverflow\bat_sql>echo exit | sqlplus -s scott/tiger@esmd @C:\upwork\stackoverflow\bat_sql\sqltest.sql
SYSDATE
--------
24.01.19
Elapsed: 00:00:00.00
C:\upwork\stackoverflow\bat_sql>pause
Например 3. Подключиться как sysdba.
rem @echo off
set user_name=sys
set password=manager
set net_service_name=esmd as sysdba
echo exit | C:\oracle\instantclient_11_2\sqlplus.exe -s %user_name%/%password%@%net_service_name% @C:\upwork\stackoverflow\bat_sql\sqltest.sql
pause
выход:
C:\upwork\stackoverflow\bat_sql>echo exit | C:\oracle\instantclient_11_2\sqlplus.exe -s sys/manageresmd@esmd as sysdba @C:\upwork\stackoverflow\bat_sql\sqltest.sql
SYSDATE
--------
24.01.19
C:\upwork\stackoverflow\bat_sql>pause
Дляпример 4. Подключаемся как sysdba.
rem @echo off
set user_name=sys
set password=manager
set net_service_name=esmd as sysdba
rem
(
echo conn %user_name%/%password%@%net_service_name%
echo @C:\upwork\stackoverflow\bat_sql\sqltest.sql
echo exit
)| sqlplus -s /nolog
pause
вывод:
C:\upwork\stackoverflow\bat_sql>(
echo conn sys/manageresmd@esmd as sysdba
echo @C:\upwork\stackoverflow\bat_sql\sqltest.sql
echo exit
) | sqlplus -s /nolog
Connected.
SYSDATE
--------
24.01.19
Elapsed: 00:00:00.00
For example sqltest.sql.
C:\upwork\stackoverflow\bat_sql>more sqltest.sql
select sysdate from dual;