2016-07-05 198 views
0

我有一个直接从shell脚本调用SQL命令的问题。我的shell脚本包含以下命令:从shell脚本调用sqlplus

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, '[email protected]') ; 
end loop ; 
end ; 

commit; 

EOF 

单命令(删除,更新)没有任何问题的完成,但THW循环似乎并没有被执行(没有语句后插入)。有谁知道这个问题可能是什么?

感谢很多提前 最良好的祝愿 约尔格

+0

fd表包含一些行吗? –

回答

0

你可以用一个SQL语句改写你的循环:

insert into rc select 1008, 1, id, '[email protected]' from fd; 

这是(我)更易读,更高效,因为它不使用PL/SQL和循环,而仅仅依赖于纯SQL。

+0

太棒了,这个工程。但是我想知道为什么PL/SQL不能以这种方式正常工作。 –

+0

也许你只是在pl/sql块后面缺少'/'? – Aleksej

+0

你是对的。我只是将我的数据库从RdB迁移到Oracle;与RdB /没有必要,所以我一直都忘记它。 谢谢你的帮助 –