2

I'm getting an error with this query:

 MERGE INTO edw_clctns_equip_dim d
   USING psa_equipment_status_history
      ON ( dw_equipment_id = TO_NUMBER (d.clctns_equip_source_id)
           AND d.active_ind = 'Y')
 WHEN MATCHED THEN
  UPDATE
     SET clctns_initial_status_date =
            (SELECT MIN (effective_date)
               FROM psa_equipment_status_history
              WHERE dw_equip_status_type_id IN (
                                       SELECT dw_equip_status_type_id
                                         FROM psa_equipment_status_type
                                        WHERE equipment_status_code = '100')
                AND current_flag = 'Y'
                AND iud_flag <> 'D'
                AND dw_equipment_id = TO_NUMBER (d.clctns_equip_source_id))

I can use the simple update query, but it is taking way too long. Does the merge statement help?

Update EDW_CLCTNS_EQUIP_DIM d
Set CLCTNS_INITIAL_STATUS_DATE =
( SELECT 
    MIN(EFFECTIVE_DATE)
  FROM PSA_EQUIPMENT_STATUS_HISTORY
  WHERE DW_EQUIP_STATUS_TYPE_ID In
  ( Select DW_EQUIP_STATUS_TYPE_ID
    From PSA_EQUIPMENT_STATUS_TYPE
    Where EQUIPMENT_STATUS_CODE = '100'
  )
  AND CURRENT_FLAG = 'Y' 
  AND IUD_FLAG<>'D'
  AND DW_EQUIPMENT_ID=to_number(d.CLCTNS_EQUIP_SOURCE_ID)
);
Peter Lang
  • 54,264
  • 27
  • 148
  • 161
Ramkumar
  • 143
  • 2
  • 12
  • Have you checked the answer to [ORA-30926: unable to get a stable set of rows in the source tables](http://stackoverflow.com/questions/2337271/ora-30926-unable-to-get-a-stable-set-of-rows-in-the-source-tables/2337465#2337465)? – Peter Lang Nov 02 '10 at 11:47
  • the psa_equipment_status_history table contained multiple entries hence the error – Ramkumar Nov 02 '10 at 12:06

2 Answers2

2

Have a look at the answer to ORA-30926: unable to get a stable set of rows in the source tables:

This is usually caused by duplicates in the query specified in USING clause.
...


Since my comment seems to have solved your problem, I posted it as answer.

Community
  • 1
  • 1
Peter Lang
  • 54,264
  • 27
  • 148
  • 161
1

yep sorry for posting the question , i was checking only the target table not the source

merge 
into EDW_CLCTNS_EQUIP_DIM d
using 
(
SELECT 
MIN(EFFECTIVE_DATE) as STATUS_DATE,DW_EQUIPMENT_ID
FROM PSA_EQUIPMENT_STATUS_HISTORY
WHERE DW_EQUIP_STATUS_TYPE_ID  in (select DW_EQUIP_STATUS_TYPE_ID from PSA_EQUIPMENT_STATUS_TYPE where EQUIPMENT_STATUS_CODE = '100')  AND 
CURRENT_FLAG = 'Y' 
AND IUD_FLAG<>'D'
group by DW_EQUIPMENT_ID
) a
on (d.CLCTNS_EQUIP_SOURCE_ID=to_char(a.DW_EQUIPMENT_ID) and d.ACTIVE_IND='Y')
WHEN MATCHED
THEN
UPDATE
SET CLCTNS_INITIAL_STATUS_DATE = a.STATUS_DATE;
Ramkumar
  • 143
  • 2
  • 12