2016-02-25 81 views
1

我有一個XMLTYPE內容,我想刪除該XML中的多個標記。Oracle刪除XMLTYPE中的多個節點

我使用XMLQUERY去除標籤recordTypeHeader裏面,像這樣:

SELECT XMLQUERY (
      'copy $i := $p modify 
        delete nodes $i//Header/recordType 
       return $i' 
      PASSING pv_header AS "p" RETURNING CONTENT) 
    INTO result 
    FROM DUAL; 

如果我想不會產生使用XMLQUERY一個新的SELECT語句刪除多個標籤。我不能做到這一點:

SELECT XMLQUERY (
       'copy $i := $p modify 
         delete nodes $i//Header/recordType 
         delete nodes $i//Header/interfaceType 
        return $i' 
       PASSING pv_header AS "p" RETURNING CONTENT) 
     INTO result 
     FROM DUAL; 

注:我可以用deleteXML但它宣佈在Oracle 12c中不推薦使用的功能。

在此先感謝! 菲利佩

編輯:我用這個作爲參考:https://docs.oracle.com/database/121/ADXDB/xdb04cre.htm#ADXDB6086

回答

1

您可以撥打delete nodes,用括號括起來的分組序列,並用逗號進行序列拼接分離:

WITH t (pv_header) AS (
    SELECT xmltype('<Header><recordType/><interfaceType/><other/></Header>') 
    FROM dual 
) 
SELECT XMLQUERY (
    'copy $i := $p modify 
    (delete nodes $i//Header/recordType, 
     delete nodes $i//Header/interfaceType) 
    return $i' 
    PASSING pv_header AS "p" RETURNING CONTENT) 
FROM t; 

XMLQUERY('COPY$I:=$PMODIFY(DELETENODES$I//HEADER/RECORDTYPE,DELETENODES$I//HEADE 
-------------------------------------------------------------------------------- 
<Header><other/></Header> 
+0

謝謝!快速簡單。我試過添加逗號,但沒有使用括號進行分組。 – milheiros