将 2 个相似的更新查询合并为一个查询
Combine 2 similar update queries into one query
update support set PH1 ='0'||PH1
where PH1 is not null;
update support set PH2 ='0'||PH2
where PH2 is not null;
有没有一种方法可以将上述两个查询(更新相同的table)组合成一个查询?
您可以使用 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
update support set PH1 ='0'||PH1
where PH1 is not null;
update support set PH2 ='0'||PH2
where PH2 is not null;
有没有一种方法可以将上述两个查询(更新相同的table)组合成一个查询?
您可以使用 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