【问题标题】:Combine 2 similar update queries into one query将 2 个相似的更新查询合并为一个查询
【发布时间】:2021-12-13 06:51:50
【问题描述】:
update support set PH1 ='0'||PH1
where PH1 is not null;


update support set PH2 ='0'||PH2
where PH2 is not null;

有没有一种方法可以将上述两个查询(更新同一个表)合并到一个查询中?

【问题讨论】:

    标签: sql oracle oracle11g oracle10g oracle-sqldeveloper


    【解决方案1】:

    您可以使用 case 表达式来实现此目的。

    UPDATE support
    SET
         PH1 = CASE WHEN PH1 IS NOT NULL THEN '0'||PH1  END,
         PH2 = CASE WHEN PH2 IS NOT NULL THEN '0'||PH2  END
    WHERE
         PH1 is not null OR PH2 is not null
    

    【讨论】:

      猜你喜欢
      • 2017-05-04
      • 1970-01-01
      • 2018-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-10
      相关资源
      最近更新 更多