日期:2014-05-17  浏览次数:21093 次

我用MERGE INTO怎么报这个错误
以下这个SQL我运行之后,报qryData:内部错误($172)
SQL code


MERGE INTO dlvr_date_mng_hdr ddh
USING(
--SQL[5-1-1]
                 SELECT
                       iv.dlvr_date_mng_num      dlvr_date_mng_num
                     , NVL(iv.dlvr_dely_day, 0)  dlvr_dely_day
                     , NVL(iv.dlvr_dely_qty, 0)  dlvr_dely_qty
                     , NVL(gdm.gnrl_cd, '0001')  gnrl_cd
                 FROM 
                     (
                     --SQL[5-1-2]
                     SELECT 
                           dpw.dlvr_date_mng_num     dlvr_date_mng_num
                         , dpw.dlvr_dely_day         dlvr_dely_day
                         , dpw.dlvr_dely_qty         dlvr_dely_qty
                         , dpw.dd_mng_mlstn_actl_flg dd_mng_mlstn_actl_flg
                     FROM 
                         dlvr_date_mng_prd_wk dpw
                     WHERE
                             dpw.dd_mng_mlstn_prcs_trgt_flg = 'Y'
                         AND dpw.delete_flag                = 'N'
                     UNION ALL
                     SELECT 
                           dlvr_date_mng_num      dlvr_date_mng_num
                         , dlvr_dely_day          dlvr_dely_day
                         , dlvr_dely_qty          dlvr_dely_qty
                         , dd_mng_mlstn_actl_flg  dd_mng_mlstn_actl_flg
                     FROM 
                         (
                         --SQL[5-1-3]
                          SELECT 
                                dtw.dlvr_date_mng_num  dlvr_date_mng_num
                              , MAX(dtw.dlvr_dely_day) dlvr_dely_day
                              , SUM(dtw.dlvr_dely_qty) dlvr_dely_qty
                              , DECODE(COUNT(DISTINCT dtw.dd_mng_mlstn_actl_flg ), 2, 'N', MIN(dtw.dd_mng_mlstn_actl_flg) ) dd_mng_mlstn_actl_flg
                         FROM 
                             dlvr_date_mng_trnpt_wk dtw
                         WHERE 
                                 dtw.dd_mng_mlstn_prcs_trgt_flg = 'Y'
                             AND dtw.delete_flag                = 'N'
                         GROUP BY
                             dtw.dlvr_date_mng_num
                         )
                     ) iv
                     , gnrl_cd_dtl_m gdm
                     , dlvr_date_mng_hdr dmh
                     , gnrl_cd_dtl_m gdmw
                 WHERE
                         iv.dlvr_date_mng_num = dmh.dlvr_date_mng_num
                     AND gdm.delete_flag      = 'N'
                     AND gdm.gnrl_cd_type_cd  = 'PRD0018'
                     AND gdm.gnrl_cd_atrbt1   = 'Y'
                     AND gdm.gnrl_cd_atrbt2   = iv.dd_mng_mlstn_actl_flg
                     AND (gdm.gnrl_cd_atrbt3 IS NULL 
                          OR gdm.gnrl_cd_atrbt3   = NVL(gdmw.gnrl_cd_atrbt3, 'N'))
                     AND gdmw.delete_flag     = 'N'
                     AND gdmw.gnrl_cd_type_cd = 'PRD0018'
                     AND gdmw.gnrl_cd         = dmh.dlvr_dely_alrt_type_cd
) ddmh 
 ON(
                ddh.dlvr_date_mng_num = ddmh.dlvr_date_mng_num
            AND ddh.glbl_bu_cd             = '002'
            AND ddh.delete_flag            = 'N'
            AND ddh.dlvr_date_mng_updt_flg = 'Y'
   )
 WHEN MATCHED THEN
            UPDATE
            SET 
              ddh.dlvr_dely_day = ddmh.dlvr_dely_day
            , ddh.dlvr_dely_qty = ddmh.dlvr_dely_qty
            , ddh.dlvr_dely_alrt_type_cd = ddmh.gnrl_cd
            , ddh.update_user_id = 'SYS'
            , ddh.update_date = SYSDATE;






------解决方案--------------------
分别执行有问题?
每个查询单独执行
------解决方案--------------------
直接执行sql语句看看吧。
------解决方案--------------------
SQL code

                 SELECT