【问题标题】:Using update from the same table with ORACLE使用 ORACLE 从同一个表中更新
【发布时间】:2022-01-07 04:03:45
【问题描述】:

我正在尝试使用同一个表中的另一个字段来更新我的表中的一个字段,但是当我在下面运行更新时出现错误

update f1
set f1.usu_cgcstr = f2.cgccpf
from E095for as f1
join E095for as f2
on f1.codfor = f2.codfor
where  f1.usu_intot = 'N'

错误:

  1. 00000 - “SQL 命令未正确结束”

那么我该如何做这个更新呢?

【问题讨论】:

    标签: sql oracle join sql-update


    【解决方案1】:

    语法错误;使用merge:

    merge into f1
      using e095for f2
      on (f1.codfor = f2.codfor)
      when matched then update set f1.usu_cgcstr = f2.cgccpf
      where f1.usu_intot = 'N';
    

    或者,如果你想要update:

    update e095for f1 set
      f1.usu_intot = (select f2.cgccpf
                      from e095for f2
                      where f2.codfor = f1.codfor
                     )
      where f1.usu_intot = 'N'
        and exists (select null from e095for c
                    where c.codfor = f1.codfor
                   );
    

    【讨论】:

    • 谢谢,使用 merge 语句解决了我的问题。
    猜你喜欢
    • 2018-07-01
    • 2023-03-08
    • 2021-02-18
    • 1970-01-01
    • 2012-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多