I have the following insert statement which fails with ORA-00001 unique constraint violated (it's a PK violation). The PK is on c_id,f_id.
INSERT
INTO ab (c_id
, d_amt
, e_date
, f_id)
SELECT c_id
, d_amt
, e_date
, (SELECT NVL(MAX(f_id) + 1,1) --this is causing the ORA-00001 error on duplicate c_id's
FROM ab
WHERE c_id = cx.c_id) f_id
FROM xx cx
My objective is to insert data from xx into ab, if there are duplicate c_id values in xx, then the insert statement should increment the f_id value by 1 for every duplicate after the first one.
mergestatement. - Gordon Linoff