Oracle表更新例外ORA-0090

时间:2014-05-08 08:19:33

标签: sql oracle

您好我正在尝试运行查询来更新我的oracle表。以下是代码

UPDATE analysis_oracle_upd t1
SET
  (c)
  =
  (SELECT t2.c FROM analysis_oracle_upd2 WHERE t1.a = t2.a
  )
WHERE EXISTS
  (SELECT 1 FROM analysis_oracle_upd2 t2 WHERE t1.a=t2.a
  );

但我得到了这个例外:

SQL Error: ORA-00904: "T2"."A": invalid identifier
00904. 00000 -  "%s: invalid identifier"

以下是两个表的架构:

create table analysis_oracle_upd (
    a number(22),
    c varchar(100),
    primary key (a));

create table analysis_oracle_upd2 (
    a number(22),
    c varchar(100),
    primary key (a));

1 个答案:

答案 0 :(得分:2)

您应该在第一个子查询中为表添加别名:

UPDATE analysis_oracle_upd t1
SET
  (c)
  =
  (SELECT t2.c FROM analysis_oracle_upd2 t2 WHERE t1.a = t2.a
  )
WHERE EXISTS
  (SELECT 1 FROM analysis_oracle_upd2 t2 WHERE t1.a=t2.a
  );