[英]Pass Parameters from a batch file to sqlplus script
I am trying to get one file with my user name and passwords for some scripts that I run every day.我正在尝试为我每天运行的某些脚本获取一个包含我的用户名和密码的文件。 I have several scripts working now using a batch file that has my user names and passwords.我现在有几个脚本正在使用一个包含我的用户名和密码的批处理文件。
My Password Batch file looks like this.我的密码批处理文件如下所示。 parms.bat参数文件
Rem Oracle Db
set odbUsername=myUserName
set odbpassword=myPassword
My other scripts call that batch file and get the information ok.我的其他脚本调用该批处理文件并正常获取信息。 I have a couple sql scripts that I also need to use these usernames and passwords.我有几个 sql 脚本,我也需要使用这些用户名和密码。 I can't seem to get them to work.我似乎无法让他们工作。 But I am fairly new to sqlplus scripting.但我对 sqlplus 脚本相当陌生。
My Sql Scripts looks like this.我的 Sql 脚本看起来像这样。
CONNECT myusername@Oracleddbname/mypassword
SET FEEDBACK OFF;
SET ECHO OFF;
SET TERMOUT OFF;
SET HEADING OFF;
SET PAGESIZE 0;
SET LINESIZE 500;
SET TIMING OFF;
SET TRIMSPOOL ON;
SET COLSEP ',';
SPOOL C:\FileTransfers\MeterData.csv
PROMPT CoopCode,MeterID,DateTime,Value
SELECT DISTINCT
a.coopcode
|| ','
|| a.meterno
|| ','
|| a.readdatetime
|| ','
|| a.usage
FROM temp_reconfigured a, temp_goodsence b
WHERE a.coopcode = b.coopcode AND a.meterno = b.meterno
;
Spool off;
EXIT;
I call this script with a batch file that runs through windows task scheduler.我使用通过 Windows 任务调度程序运行的批处理文件调用此脚本。
It looks like this.它看起来像这样。
sqlplus /nolog @C:\FileTransfers\AutomationScripts\GoodSence\SpoolGoodSenceDataSet.sql
So I would like to pass the user name to the sql from the batch file.所以我想将用户名从批处理文件传递给sql。 I have read several things and tried about 30 and none seem to work.我已经阅读了几篇文章并尝试了大约 30 篇,但似乎都没有奏效。 Thank you for your help in advance.提前谢谢你的帮助。
You can pass a parameter this way:您可以通过以下方式传递参数:
script.sql:脚本.sql:
select '&1' from dual;
the call:电话:
D:\>sqlplus user/password@db @d:\script.sql 'value'
SQL*Plus: Release 11.2.0.2.0 Production on Lun Ott 3 17:02:10 2016
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
old 1: select '&1' from dual
new 1: select 'value' from dual
'VALU
-----
value
Just typing that out made me think about passing it during the call vs inside the sql to connect.只是输入它让我考虑在调用期间传递它与在 sql 内部进行连接。 I then edited my SQL and took out the connect statement然后我编辑了我的 SQL 并取出了连接语句
So this worked...所以这有效...
echo Get Parameters
call C:\FileTransfers\AutomationScripts\parms.bat
echo %odbUsername%
echo %odbpassword%
sqlplus myusername@oracledb/%odbpassword%@C:\FileTransfers\AutomationScripts\GoodSence\SpoolGoodSenceDataSet.sql
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.