【问题标题】:sqlplus called from shell script从 shell 脚本调用的 sqlplus
【发布时间】:2016-07-05 17:59:32
【问题描述】:

我在直接从 shell 脚本调用 SQL 命令时遇到问题。我的 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

单个命令(删除、更新)完成没有任何问题,但似乎没有执行 thw 循环(语句后没有插入任何内容)。有人知道问题可能是什么吗?

提前非常感谢 最好的祝愿 约尔格

【问题讨论】:

  • fd 表包含一些行?

标签: oracle shell sqlplus


【解决方案1】:

你可以用一条 SQL 语句重写你的循环:

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

这(对我而言)更具可读性和效率,因为它不使用 PL/SQL 和循环,而仅依赖于纯 SQL。

【讨论】:

  • 太好了,这行得通。但我会感兴趣为什么 PL/SQL 不能以这种方式正常工作。
  • 也许您只是在 pl/sql 块之后缺少“/”?
  • 你是对的。我只是将我的数据库从 RdB 迁移到 Oracle;使用 RdB 时 / 是不必要的,所以我一直都忘记它。谢谢四位的帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-26
  • 1970-01-01
  • 2019-03-09
  • 1970-01-01
相关资源
最近更新 更多