运行合并到查询时出现ORA-30926错误

时间:2010-11-02 11:38:38

标签: sql oracle merge

我的查询出错:

 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))

我可以使用简单的更新查询,但它花了太长时间。合并声明有帮助吗?

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)
);

2 个答案:

答案 0 :(得分:2)

查看ORA-30926: unable to get a stable set of rows in the source tables的答案:

  

这通常是由USING子句中指定的查询中的重复引起的   ...


由于我的评论似乎已经解决了您的问题,我将其作为答案发布。

答案 1 :(得分:1)

对不起发布问题,我只检查目标表而非源

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;