如果从以下查询中删除exists语句,我的输出将如何更改。
UPDATE AR_CRDT C
set (OPERATOR_ID,UPDT_TS) = ( SELECT AD.OPERATOR_ID,sysdate
FROM
(
Select A.*
FROM AR1_CUSTOMER_CREDIT A
)AD
WHERE AD.CREDIT_ID = C.CRDT_ID
)
where exists ( SELECT 1
FROM
(
Select A.*
FROM AR1_CUSTOMER_CREDIT A
)AD
WHERE AD.CREDIT_ID = C.CRDT_ID
);
答案 0 :(得分:2)
如果您删除了exists
,那么OPERATOR_ID
和UPDT_TS
会针对条件不匹配的行设置为NULL
。
为什么要用额外的子查询来写这个?
UPDATE AR_CRDT C
SET (OPERATOR_ID, UPDT_TS) = (SELECT AD.OPERATOR_ID, sysdate
FROM AR1_CUSTOMER_CREDIT A
WHERE A.CREDIT_ID = C.CRDT_ID
)
WHERE EXISTS (SELECT 1
FROM AR1_CUSTOMER_CREDIT A
WHERE A.CREDIT_ID = C.CRDT_ID
);
答案 1 :(得分:2)
EXISTS当前导致AR_CRDT的更新仅限于AR_CRDT记录与AR1_CUSTOMER_CREDIT记录相关联的记录。
删除该子句意味着将更新AR_CRDT的所有记录。一些将具有子查询的值,一些将为NULL,其中AR_CRDT和AR1_CUSTOMER_CREDIT之间没有链接。