sqlplus在bash上输入重定向

时间:2015-08-13 20:33:54

标签: linux bash sqlplus

sqlplus / bash脚本新手。我目前有一个简单的脚本,它根据一些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.

如果不必手动输入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.

这会有用吗?我目前无法访问学校实验室几天,所以我现在无法对此进行测试。 有没有更好更有效的方法呢?

1 个答案:

答案 0 :(得分:0)

试试这个:

 sqlplus -S  /nolog <<_EOD1

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