我在 Oracle DB 中有一個臨時表,其中加載了資料,表名是 pc_stg_auth。它有 4 個 PK。我必須將這 4 個 PK 與另一個名為 autho_activity_msc 的表匹配,如果 PK 匹配,那么我必須從名為 pc_stg_auth 的臨時表以及 autho_activity_msc 中洗掉記錄。
我正在使用以下查詢,但它給了我一個語法錯誤:
delete autho_activity_msc , pc_stg_auth from autho_activity_msc inner join pc_stg_auth
where autho_activity_msc.reference_number = pc_stg_auth.reference_number AND
autho_activity_msc.external_stan = pc_stg_auth.external_stan AND
autho_activity_msc.routing_code = pc_stg_auth.routing_code AND
autho_activity_msc.capture_code = pc_stg_auth.capture_code;
commit;
下面是錯誤:
line 1: ORA-00933: SQL command not properly ended
請幫助或建議是否有更簡單的方法來實作它。
uj5u.com熱心網友回復:
Oracle 不支持該語法。
您需要使用多個DELETE陳述句。您可以從一個表中洗掉匹配的行并將匹配的鍵收集到集合中,然后遍歷集合并洗掉第二個表中的所有行:
DECLARE
rns SYS.ODCINUMBERLIST;
ess SYS.ODCINUMBERLIST;
rcs SYS.ODCINUMBERLIST;
ccs SYS.ODCINUMBERLIST;
BEGIN
DELETE FROM pc_stg_auth
WHERE (reference_number, external_stan, routing_code, capture_code)
IN (SELECT reference_number, external_stan, routing_code, capture_code
FROM autho_activity_msc)
RETURNING reference_number, external_stan, routing_code, capture_code
BULK COLLECT INTO rns, ess, rcs, ccs;
FORALL i IN 1 .. rns.COUNT
DELETE FROM autho_activity_msc
WHERE reference_number = rns(i)
AND external_stan = ess(i)
AND routing_code = rcs(i)
AND capture_code = ccs(i);
COMMIT;
END;
/
db<>在這里擺弄
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/474665.html
