我想对递归查询返回的结果集执行各种更新,而不必为每次更新重写递归查询?
有没有办法将每个 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));