ORA-30926 error when running the merge into query
I'm getting an 开发者_如何学Goerror 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)
);
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.
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;
精彩评论