Saturday, January 9, 2021

How to insert duplicate records into one table and non-duplicate records into another table using single DML operation (Oracle DB)?

 Input:


NONDUP_REC:

DUP_REC:

Query:

DUP_RECORDS_SPLIT Data:


INSERT FIRST 
WHEN RNK = 1 THEN 
    INTO NONDUP_REC VALUES (SID,SNAME,MARKS)
ELSE 
    INTO DUP_REC VALUES (SID,SNAME,MARKS)
SELECT * FROM
(SELECT SID,SNAME,MARKS, COUNT(SID) OVER (PARTITION BY SID ORDER BY SID) RNK FROM DUP_RECORDS_SPLIT);

COMMIT;


No comments:

Post a Comment