我想使用merge语句更新存在的行,或者如果不存在则在Table中插入新行。可以使用MERGE完成
MERGE into BANK_DETAILS A using ( SELECT * FROM BANK_DETAILS ) B ON (A.BANKID=<<>> AND A.COUNTRY=<<>>)
WHEN MATCHED THEN
UPDATE SET A.STATUS=<<condiition>>, A.IS_BLOCKED=<<>> , A.IS_DISABLED=<<>>,A.LOGO=<<>>,a.BANK_GROUP=<<>>,A.LAST_MODIFIED_DATE=<<>>,A.LAST_MODIFIED_BY=<<>>
WHEN NOT MATCHED THEN
INSERT (A.ID,A.BANKID,A.COUNTRY,A.BANKNAME,A.LOGO,A.STATUS,A.IS_BLOCKED,A.IS_DISABLED,A.BANK_GROUP,A.CREATED_DATE,A.CREATED_BY,A.LAST_MODIFIED_DATE,A.LAST_MODIFIED_BY)
VALUES (BANK_DETAILS_ID_SEQ.NEXTVAL,?,?,?,?,?,?,?,?,sysdate,?,sysdate,?)
;
答案 0 :(得分:0)
是的,只需从dual
子句中的USING
中选择值,而不是bank_details
MERGE INTO bank_details a USING ( SELECT 2345 as bankid,
'India' as country,
'SBI' as bankname,
..
..
...
FROM dual ) b ON ( .. )
..
..
UPDATE SET A.status= b.status, a.is_blocked = b.is_blocked,..
...
...
VALUES
( bank_details_id_seq.NEXTVAL,b.bankid,b.country,?,?,?,?,?,?,
SYSDATE,?,SYSDATE,? );