如何提取与XML.extract同级的标签?
How to extract tags at the same level with XML.extract?
通过此查询,我获取了标记 ROW 内的所有内容。
但我想把所有东西都带上标签 .
select xmltype(
'<?xml version="1.0"?>
<ROWSET>
<ROW>
<PERSON_NUMBER>1000142</PERSON_NUMBER>
<LOAN_1>25000</LOAN_1>
</ROW>
<ROW>
<PERSON_NUMBER>1000142</PERSON_NUMBER>
<LOAN_1>25000</LOAN_1>
</ROW>
</ROWSET>'
).extract( '/ROWSET/ROW' ) .getstringval() p#
from dual;
我可以select子标签
select xmltype(
'<?xml version="1.0"?>
<ROWSET>
<ROW>
<PERSON_NUMBER>1000142</PERSON_NUMBER>
<LOAN_1>25000</LOAN_1>
<field_without_interest>f</field_without_interest>
</ROW>
<ROW>
<PERSON_NUMBER>1000142</PERSON_NUMBER>
<LOAN_1>25000</LOAN_1>
</ROW>
</ROWSET>'
).extract( '/ROWSET/ROW/PERSON_NUMBER' ) .getstringval() p#
from dual;
但我select只关注我感兴趣的一半标签。
有没有办法写extract( '/ROWSET/ROW/PERSON_NUMBER' AND '/ROWSET/ROW/LOAN_1' )
要么
extract( '/ROWSET/ROW/ except'/ROWSET/ROW/field_without_interest' )
您可以使用 XMLQUERY
和 FLOWR。
如果您只想要第一个 ROW
那么:
SELECT XMLQUERY(
'copy $NEWHTML := /ROWSET/ROW[1]
modify (
for $i in $NEWHTML/field_without_interest
return delete node $i
)
return $NEWHTML/*'
PASSING xmltype(
'<?xml version="1.0"?>
<ROWSET>
<ROW>
<PERSON_NUMBER>1000142</PERSON_NUMBER>
<LOAN_1>25000</LOAN_1>
<field_without_interest>f</field_without_interest>
</ROW>
<ROW>
<PERSON_NUMBER>1000142</PERSON_NUMBER>
<LOAN_1>25000</LOAN_1>
</ROW>
</ROWSET>'
)
RETURNING CONTENT
).getStringVal() AS interested_elements
FROM DUAL;
输出:
INTERESTED_ELEMENTS
<PERSON_NUMBER>1000142</PERSON_NUMBER><LOAN_1>25000</LOAN_1>
或者,如果您想要整个 ROWSET
,您可以使用:
SELECT XMLQUERY(
'copy $NEWHTML := .
modify (
for $i in $NEWHTML/ROWSET/ROW/field_without_interest
return delete node $i
)
return $NEWHTML'
PASSING xmltype(
'<?xml version="1.0"?>
<ROWSET>
<ROW>
<PERSON_NUMBER>1000142</PERSON_NUMBER>
<LOAN_1>25000</LOAN_1>
<field_without_interest>f</field_without_interest>
</ROW>
<ROW>
<PERSON_NUMBER>1000142</PERSON_NUMBER>
<LOAN_1>25000</LOAN_1>
</ROW>
</ROWSET>'
)
RETURNING CONTENT
).getStringVal() AS interested_elements
FROM DUAL;
输出:
INTERESTED_ELEMENTS
<?xml version="1.0"?><ROWSET><ROW><PERSON_NUMBER>1000142</PERSON_NUMBER><LOAN_1>25000</LOAN_1></ROW><ROW><PERSON_NUMBER>1000142</PERSON_NUMBER><LOAN_1>25000</LOAN_1></ROW></ROWSET>
db<>fiddle here
通过此查询,我获取了标记 ROW 内的所有内容。
但我想把所有东西都带上标签
select xmltype(
'<?xml version="1.0"?>
<ROWSET>
<ROW>
<PERSON_NUMBER>1000142</PERSON_NUMBER>
<LOAN_1>25000</LOAN_1>
</ROW>
<ROW>
<PERSON_NUMBER>1000142</PERSON_NUMBER>
<LOAN_1>25000</LOAN_1>
</ROW>
</ROWSET>'
).extract( '/ROWSET/ROW' ) .getstringval() p#
from dual;
我可以select子标签
select xmltype(
'<?xml version="1.0"?>
<ROWSET>
<ROW>
<PERSON_NUMBER>1000142</PERSON_NUMBER>
<LOAN_1>25000</LOAN_1>
<field_without_interest>f</field_without_interest>
</ROW>
<ROW>
<PERSON_NUMBER>1000142</PERSON_NUMBER>
<LOAN_1>25000</LOAN_1>
</ROW>
</ROWSET>'
).extract( '/ROWSET/ROW/PERSON_NUMBER' ) .getstringval() p#
from dual;
但我select只关注我感兴趣的一半标签。
有没有办法写extract( '/ROWSET/ROW/PERSON_NUMBER' AND '/ROWSET/ROW/LOAN_1' )
要么
extract( '/ROWSET/ROW/ except'/ROWSET/ROW/field_without_interest' )
您可以使用 XMLQUERY
和 FLOWR。
如果您只想要第一个 ROW
那么:
SELECT XMLQUERY(
'copy $NEWHTML := /ROWSET/ROW[1]
modify (
for $i in $NEWHTML/field_without_interest
return delete node $i
)
return $NEWHTML/*'
PASSING xmltype(
'<?xml version="1.0"?>
<ROWSET>
<ROW>
<PERSON_NUMBER>1000142</PERSON_NUMBER>
<LOAN_1>25000</LOAN_1>
<field_without_interest>f</field_without_interest>
</ROW>
<ROW>
<PERSON_NUMBER>1000142</PERSON_NUMBER>
<LOAN_1>25000</LOAN_1>
</ROW>
</ROWSET>'
)
RETURNING CONTENT
).getStringVal() AS interested_elements
FROM DUAL;
输出:
INTERESTED_ELEMENTS <PERSON_NUMBER>1000142</PERSON_NUMBER><LOAN_1>25000</LOAN_1>
或者,如果您想要整个 ROWSET
,您可以使用:
SELECT XMLQUERY(
'copy $NEWHTML := .
modify (
for $i in $NEWHTML/ROWSET/ROW/field_without_interest
return delete node $i
)
return $NEWHTML'
PASSING xmltype(
'<?xml version="1.0"?>
<ROWSET>
<ROW>
<PERSON_NUMBER>1000142</PERSON_NUMBER>
<LOAN_1>25000</LOAN_1>
<field_without_interest>f</field_without_interest>
</ROW>
<ROW>
<PERSON_NUMBER>1000142</PERSON_NUMBER>
<LOAN_1>25000</LOAN_1>
</ROW>
</ROWSET>'
)
RETURNING CONTENT
).getStringVal() AS interested_elements
FROM DUAL;
输出:
INTERESTED_ELEMENTS <?xml version="1.0"?><ROWSET><ROW><PERSON_NUMBER>1000142</PERSON_NUMBER><LOAN_1>25000</LOAN_1></ROW><ROW><PERSON_NUMBER>1000142</PERSON_NUMBER><LOAN_1>25000</LOAN_1></ROW></ROWSET>
db<>fiddle here