简体   繁体   English

bash上的sqlplus输入重定向

[英]sqlplus Input redirection on bash

New to sqlplus/bash scripting. sqlplus / bash脚本编写的新功能。 I currently have a simple script that fetches some value in a table based on some ID values. 我目前有一个简单的脚本,可以根据一些ID值在表中获取一些值。

#do things. get login info. etc....
(cat<<HERE
set heading off;
select data_value from metadata where name='JOHN' and uniqueid in (1, 2, 3);
EOD
) | sqlplus -S $login
#do things.

What if instead of having to manually type of the ids (1, 2, 3, etc...), I do this: 如果我不必手动输入ID(1、2、3等),该怎么办:

#calls a script that gets the IDs from somewhere and outputs it in the correct format    
./getIDscript > IDs
#do things. get login info. etc....
(cat<<HERE
set heading off;
select data_value from metadata where name='JOHN' and uniqueid in ($IDs);
EOD
) | sqlplus -S $login
#do things.

Would this work? 这行得通吗? I currently won't have access to the school lab for a few days so I can't test this out right now. 我目前几天都无法访问学校实验室,因此我现在无法测试。 Is there a better and more efficient way of doing this? 有没有更好,更有效的方法?

Try this : 尝试这个 :

 sqlplus -S  /nolog <<_EOD1

 WHENEVER SQLERROR EXIT SQL.SQLCODE
 connect   usr/xxx@db1
 select 1 from dual
 /
 exit
_EOD1

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

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