0

我想对递归查询返回的结果集执行各种更新,而不必为每次更新重写递归查询?

有没有办法将每个 UPDATE 彼此分隔?

这是我的代码:

WITH IDS (Level, $COID, $COID_REF, $CONAME) AS
  (SELECT 0, x.$COID, x.$COID_REF, x.$CONAME
    FROM MCINT.$EXT x
    WHERE $COID = X'1234567890123456'
  UNION ALL
  SELECT B.Level + 1, c.$COID, c.$COID_REF, c.$CONAME
    FROM IDS B, MCINT.$EXT C
    WHERE B.$COID_REF = C.$COID AND B.Level < 30)

-- perform first update on ther result set
SELECT COUNT(*) AS updated_rows
  FROM  FINAL TABLE
    (UPDATE MCINT.$EXT_LF 
        SET $CUR_ACC_MET_DATA = REPLACE($CUR_ACC_MET_DATA, 'p_mcint', 't_mcint')
     WHERE $COID IN (SELECT $COID_REF FROM IDS));

-- second recursive scan
WITH IDS (Level, $COID, $COID_REF, $CONAME) AS
  (SELECT 0, x.$COID, x.$COID_REF, x.$CONAME
    FROM MCINT.$EXT x
    WHERE $COID = X'1234567890123456'
  UNION ALL
  SELECT B.Level + 1, c.$COID, c.$COID_REF, c.$CONAME
    FROM IDS B, MCINT.$EXT C
    WHERE B.$COID_REF = C.$COID AND B.Level < 30)

-- perform second update on the result set
SELECT COUNT(*) AS updated_rows
  FROM  FINAL TABLE
    (UPDATE MCINT.$EXT_LF 
        SET $CUR_ACC_MET_DATA = REPLACE($CUR_ACC_MET_DATA, 'p_xcdata', 't_xcdata')
     WHERE $COID IN (SELECT $COID_REF FROM IDS));
4

1 回答 1

0

除非我遗漏了什么,否则这两种说法的不同之处仅在于:

SET $CUR_ACC_MET_DATA = REPLACE($CUR_ACC_MET_DATA, 'p_mcint', 't_mcint')

对比

SET $CUR_ACC_MET_DATA = REPLACE($CUR_ACC_MET_DATA, 'p_xcdata', 't_xcdata')

如果是这种情况,您可以通过一次更新来做到这一点:

SET $CUR_ACC_MET_DATA = REPLACE(REPLACE($CUR_ACC_MET_DATA, 'p_mcint', 't_mcint'),
                                'p_xcdata', 't_xcdata')
于 2013-06-13T18:36:23.063 回答