I am working with both PostgreSQL and oracle for same query. while updating using PostgreSQL, remaining entries gets delete and whichever matched get update. Same query using merge in oracle didn't delete non-updated entries.
Postgres query:
<pre><code>
`INSERT INTO IAG_PERMISSION(id,bid,aid,s_type,subject,r_type,object,permissions,tid,person)
VALUES(?,?,?,?,?,?,?,?,?,?)
ON CONFLICT ON CONSTRAINT IAG_PERM_UK1
DO
UPDATE SET SUBJECT=?,PERMISSIONS=?`
</code></pre>
Oracle Query:
<pre><code>
`MERGE INTO IAG_PERMISSION iap
USING dual
ON (iap.AID = ?
AND iap.R_TYPE = ?
AND iap.OBJECT = ?
AND iap.R_TYPE = ?
AND iap.PERSON = ? )
WHEN MATCHED THEN UPDATE SET SUBJECT = ? , PERMISSIONS = ?
WHEN NOT MATCHED THEN INSERT (iap.id,iap.bid,iap.aid,iap.s_type,iap.subject,iap.r_type,iap.object,iap.permissions,iap.tid,iap.person)
VALUES (?,?,?,?,?,?,?,?,?,?`);
`
</code></pre>
This are the both query I want oracle query to work same as postgres and delete not update query when matched, I tries using delete statement but its not working. Oracle document stated that used delete where clause to clean up data but not working in my case. I am unable to understand what I am doing wrong.
Delete not working while doing insert and update using merge. Thank you in advance.
Query which I tried:
<pre><code>
`MERGE INTO IAG_PERMISSION IAP
USING dual d
ON (iap.id='AccessDataStaging' AND iap.R_TYPE ='App1' AND iap.OBJECT ='Obj' AND iap.S_type ='User'
AND iap.PERSON ='Application New')
WHEN NOT MATCHED THEN INSERT(iap.id,iap.bid,iap.aid,iap.s_type,iap.subject,iap.r_type,iap.object,iap.permissions,iap.tid,iap.person)
VALUES ('of2167aa-769e-4621-b7ff-61b2f44741ea',64, 'AccessDataStaging','User','Sakshi','App1','Obj','N',64,'Application New')
WHEN MATCHED THEN UPDATE SET iap. Subject = 'Sakshi', iap. PERMISSIONS ='K'
DELETE WHERE iap.PERSON='Application New' AND iap. Permissions != 'K';
`
</code></pre>