1
MERGE INTO A
USING (  
    SELECT B_1,B_2,B_3,SUM(B_4)
    FROM B
    GROUP BY B_1,B_2,B_3) srt
ON (
    A.A_1 = B.B_1
    AND NVL (A.A_2, 0) =
            NVL (B.B_2, 0)
    AND NVL (A.A_3, ' ') =
            NVL (B.B_3, ' ') )
WHEN MATCHED
THEN   'DML STATEMENT';

Above throws an error

Caused by: java.sql.SQLException: ORA-06502: PL/SQL: numeric or value error: character to number conversion error ORA-30926: unable to get a stable set of rows in the source tables

But when you replace the above query with below NVL(EXPR, -1) it works without any error. Any reason one can foresee I am unable to see?

MERGE INTO A
USING (  
    SELECT B_1,B_2,B_3,SUM(B_4)
    FROM B
    GROUP BY B_1,B_2,B_3) srt
ON (
    A.A_1 = B.B_1
    AND NVL (A.A_2, -1) =
            NVL (B.B_2, -1)
    AND NVL (A.A_3, ' ') =
            NVL (B.B_3, ' ') )
WHEN MATCHED
THEN   'DML STATEMENT';
Pham X. Bach
  • 5,284
  • 4
  • 28
  • 42
Rohan K
  • 177
  • 1
  • 3
  • 21

1 Answers1

2

Though your two queries looks similar, they may behave differently due to NVL function used in ON clause Columns. Analyzing above two queries and their results, what I concluded is that either of Columns A.A_2 and B.B_2 must have values both NULL and 0(but not the value -1).

To resolve "unable to get a stable set of rows in the source tables", you have to use the same NVL function in GROUP BY sub-query that is being used in ON clause.

Ram Limbu
  • 432
  • 3
  • 8
  • 15