我有一个XMLTYPE内容,我想删除该XML中的多个标记。
我正在使用XMLQUERY删除recordType
中的代码Header
,如下所示:
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
答案 0 :(得分: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>