0

I am trying to update a table in a database using another table in another database. This script was working fine until recently when I started getting the error: ORA-30926: unable to get a stable set of rows in the source tables.

Please find the Script below.

MERGE INTO VANTAGEDB.CERT_UPLOAD A
     USING (
              SELECT PERSONNEL_ID,
                     SURNAME,
                     FORENAMES,
                     BIRTH_DATE
                FROM PERSONNEL@ORA12C_TO_POBM
               WHERE REMARK LIKE 'PORTAL_VANTAGE%'
           ) B
        ON (    A.SURNAME = B.SURNAME
            AND A.FORENAMES = B.FORENAMES
            AND A.BIRTH_DATE = B.BIRTH_DATE)
WHEN MATCHED
THEN
   UPDATE SET A.PERSONNEL_ID = B.PERSONNEL_ID
           WHERE     NOT REGEXP_LIKE (PERSONNEL_ID, '^[[:digit:]]+$')
                 AND CERT_STATUS IS NULL;

I have run these embedded scripts alone and they worked fine. What do i do please?

4
  • Are there any duplicates in PERSONNEL table?
    – Littlefoot
    Commented Apr 5 at 6:00
  • @Littlefoot, personnel table does not allow duplicates.
    – POB SISO
    Commented Apr 5 at 6:54
  • It means that select surname, forename, birth_date from personnel group by surname, forename, birth_date having count(*) > 1 doesn't return anything? Can you run it to verify that statement?
    – Littlefoot
    Commented Apr 5 at 6:57
  • It returned 76 rows. However, if i add personnel_id column to it, it returned nothing because personnel_id is a unique identifier. Does this mean that these 76 entries were the ones giving issues?
    – POB SISO
    Commented Apr 5 at 7:23

1 Answer 1

1

(This can't fit into a comment and I can't format code there).

Apparently,

select surname, forename, birth_date 
from personnel 
group by surname, forename, birth_date 
having count(*) > 1;

returns some duplicates.

That's the cause of your problems because you're using these 3 columns while joining target table (CERT_UPLOAD) to source data set (subquery). As there are duplicates, Oracle doesn't know which PERSONNEL_ID to take.

For example, if cert_upload contains

surname forename birth_date personnel_id
------- -------- ---------- ------------
White   Mike     10.01.2020       (NULL)

and subquery returned

surname forename birth_date personnel_id
------- -------- ---------- ------------ 
White   Mike     10.01.2020          100
White   Mike     10.01.2020          992

which personnel_id (100 or 992) should be put into cert_upload table? I don't know, Oracle doesn't know it either.

It means that you'll have to include additional column(s) to uniquely identify each row so that join would be 1:1.

2
  • 1
    Thank you so much @littlefoot, i got the particular one giving issues when i added the where statement (WHERE REMARK LIKE'PORTAL_VANTAGE%') into your script above, i got the entry that wasn't supposed to be in the table.
    – POB SISO
    Commented Apr 5 at 8:00
  • Excellent! I'm glad you made it! Thank you for letting us know.
    – Littlefoot
    Commented Apr 5 at 9:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.