简体   繁体   English

从Shell脚本调用的sqlplus

[英]sqlplus called from shell script

I have a problem calling SQL commands directly from a shell script. 我直接从Shell脚本调用SQL命令时遇到问题。 My shell script contains the following commands: 我的shell脚本包含以下命令:

set x = `sqlplus -S $ISLK_ORACLE_UID` <<EOF

delete from rc where rcd_id = 1 ;
update rcd set standard = 'Test_DB7' where id = 1 ;
delete from rc where rcd_id = 2 ;
update rcd set standard = '700' where id = 2 ;
delete from rc where rcd_id = 5 ;
update rcd set standard = 'DB7' where id = 5 ;
delete from rc where rcd_id = 998 ;
update rcd set standard = '2001-2050' where id = 998 ;

delete from rc where rcd_id=3004 ;

begin
for fd_rec in (select * from fd)
loop
   insert into rc values(1008, 1, fd_rec.id, 'islk.am@swisscom.com') ;
end loop ;
end ;

commit;

EOF

The single commands (delete, update) are completed without any problems, but thw loop seems not to be performed (nothing inserted after statement). 单个命令(删除,更新)已完成,没有任何问题,但似乎未执行循环(在语句后未插入任何内容)。 Has anybody an idea what the problem might be? 有谁知道可能是什么问题?

Thanks a lot in advance Best wishes Jörg 在此先多谢您衷心祝愿约尔格

You could rewrite your loop with a single SQL statement: 您可以使用单个SQL语句重写循环:

insert into rc select 1008, 1, id, 'islk.am@swisscom.com' from fd;

This is (to me) more readable and more efficient, given that it uses no PL/SQL and loops, but simply relies on pure SQL. (对我而言)这更易读和更高效,因为它不使用PL / SQL和循环,而仅依赖纯SQL。

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

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