简体   繁体   English

如何使用批处理文件将绑定变量值传递给 SQLplus

[英]How to pass Bind variable value to SQLplus using Batch file

I want to pass a value to Sqlplus using batch file and store the output in excel.我想使用批处理文件将一个值传递给 Sqlplus,并将 output 存储在 excel 中。

SQL code:

Select :v_customerName||'|'||id||'|'||SUBMISSION_DATE||'|'||VALUE
from job_summary 

In job_summary table, i have only 3 columns(id,date,value).I have to pass a customer name using batch file.在 job_summary 表中,我只有 3 列(id、日期、值)。我必须使用批处理文件传递客户名称。

MY OUTPUT in Excel:
  |1|1-may-20|234
  |2|4-may-20|235
Output I want:
  abc|1|1-may-20|234
  abc|2|4-may-20|235

I don't now how to pase the value for customer in batch script.我现在不知道如何在批处理脚本中为客户传递价值。

My batch:
sqlplus hr/hr@ @Header.sql !customername!

.SQL script contents: .SQL脚本内容:

set colsep ';'
set ver off
set heading off
spool a.txt

select '&1', ename, job
from emp
where deptno = 10;

spool off
exit

Call it as follows;调用如下; Littlefoot is parameter you want to see in the output file: Littlefoot是你想在 output 文件中看到的参数:

c:\Temp>sqlplus scott/tiger @p Littlefoot

SQL*Plus: Release 11.2.0.2.0 Production on Uto Svi 12 07:14:38 2020

Copyright (c) 1982, 2014, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production


Littlefoot;CLARK     ;MANAGER
Littlefoot;KING      ;PRESIDENT
Littlefoot;MILLER    ;CLERK

Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

c:\Temp>

Result:结果:

c:\Temp>type a.txt

Littlefoot;CLARK     ;MANAGER
Littlefoot;KING      ;PRESIDENT
Littlefoot;MILLER    ;CLERK


c:\Temp>

So:所以:

  • just pass the parameter传递参数
  • reference it (in .sql script) with the & sign使用&符号引用它(在.sql脚本中)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM