请问下面的更新语句怎么写?

Functions 2005-01-17 04:49:50
我用表TableB中的NameA 更新表TableA中的Name列,两个表用ID关联。在MSS中这样写:
UPDATE TableA
SET Name = NameA
FROM TableB as B
WHERE B.ID = TableA.ID

在ora中如何实现?
刚用ora,不大熟悉。
...全文
109 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Functions 2005-01-19
  • 打赏
  • 举报
回复
TO:tian00weiwei(weiwei)
我创建如下存储过程
==========================================================================
create or replace procedure sp_test123 is
begin
for i in select a,b from aa1 where aa1.a = aa2.a
update aa2
set b=i.b
where a=i.a;

end sp_test123;

出现如下错误信息(for行的最后也测试过有分号的,也有错误,不大一样):
--------------------------------------------------------------------------

Compilation errors for PROCEDURE CICF.SP_TEST123

Error: PLS-00103: 出现符号 "SELECT"在需要下列之一时:
( - + case mod new null
<an identifier> <a double-quoted delimited-identifier>
<a bind variable> reverse avg count current max min prior sql
stddev sum variance execute forall merge <a SQL statement>
time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
符号 "(" 被替换为 "SELECT" 后继续。
Line: 3
Text: for i in select a,b from aa1 where aa1.a = aa2.a;

Error: PLS-00103: 出现符号 ";"在需要下列之一时:
. ( ) * @ % & - + / at for
mod rem <an exponent (**)> and or group having intersect
minus order start union where connect ||
Line: 3
Text: for i in select a,b from aa1 where aa1.a = aa2.a;

Error: PLS-00103: 出现符号 "end-of-file"在需要下列之一时:
end not pragma
final instantiable order overriding static member constructor
map
Line: 9
==========================================================================

在SQL Plus中,出现如下信息:

未知的命令开头 "for i in s..." - 忽略了剩余的行。
==========================================================================
我对Oracle不熟悉,请问是什么原因?
Functions 2005-01-17
  • 打赏
  • 举报
回复
谢谢二位。
我用ORARichard(没钱的日子......) 的方法解决了。
tian00weiwei(weiwei) 的方法很特别,等我测试通过,立刻结分。
tian00weiwei 2005-01-17
  • 打赏
  • 举报
回复
for i in select id,namea from tableb where tableb.id=tablea.id;
update tablea
set name=i.namea
where id=i.id;
ORARichard 2005-01-17
  • 打赏
  • 举报
回复
UPDATE TableA a
SET a.Name = (select b.NameA FROM TableB B WHERE B.ID = a.ID)
where exists(select 1 from TableB B WHERE B.ID = a.ID);

17,089

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧