假设此脚本 use_arg.sql :
PROMPT Arg1=&1, Arg2=&2
从windows cmd,我可以将其称为
echo exit | sqlplus user/pw@db @use_arg a b
,结果是
SQL*Plus: Release 11.2.0.3.0 Production on Tue Feb 16 12:10:07 2016
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Arg1=a, Arg2=b
SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
我试过
echo exit | sqlplus user@db @use_arg a b
但是Sqlplus将使用“exit”作为密码。
答案 0 :(得分:2)
您可以使用'heredoc'生成临时脚本;来自批处理文件:
@(
echo connect user/pw@db
echo @use_arg a b
echo exit
) | sqlplus.exe -s /nolog
我已经包含了-s标志来减少输出:
C:\Users\some\path>use_arg.bat
Arg1=a, Arg2=b
或者,如果您想提供用户名和TNS别名但提示输入密码,您可以创建一个临时脚本并运行该脚本:
@echo @use_arg a b > use_arg_exit.tmp
@echo exit >> use_arg_exit.tmp
@sqlplus.exe -s user@db @use_arg_exit.tmp
@del use_arg_exit.tmp
运行方式:
C:\Users\some\path>use_arg.bat
Enter password:
Arg1=a, Arg2=b
当然,您可以将临时文件放在工作目录以外的某个位置,并且需要对其进行命名,以便它不会覆盖您关心的真实文件。