读取 XML 格式的字符串并使用 PL SQL 中的 for 循环进行更新

Posted

技术标签:

【中文标题】读取 XML 格式的字符串并使用 PL SQL 中的 for 循环进行更新【英文标题】:Read string in XML format and update with a for loop in PL SQL 【发布时间】:2021-09-13 13:52:39 【问题描述】:

我是 PL SQL 的新手,需要更新包含许多记录的列。 该列基本上是 xml 格式的字符串。 这是一个例子:

<indexes>
<index>
    <date_format>dd-MM-yyyy</date_format>
    <name>ID_TEST</name>
    <required>true</required>
    <value>123456789</value>
</index>
<index>
    <date_format>dd-MM-yyyy</date_format>
    <name>NUMBER_TEST</name>
    <required>true</required>
    <value>123</value>
</index>

我需要在所有索引标签的开头添加一个新标签,如示例所示:

<indexes>
<index>
    <NEW_TAG>abcdef</NEW_TAG>
    <date_format>dd-MM-yyyy</date_format>
    <name>ID_TEST</name>
    <required>true</required>
    <value>123456789</value>
</index>
<index>
    <NEW_TAG>abcdef</NEW_TAG>
    <date_format>dd-MM-yyyy</date_format>
    <name>NUMBER_TEST</name>
    <required>true</required>
    <value>123</value>
</index>

提前谢谢大家

【问题讨论】:

【参考方案1】:

希望这会有所帮助:

select appendchildxml(
xmltype(your_xml)
, '/indexes/index[1]' -- replace the 1 with index instance number
, xmlelement("NEW_TAG")
).getclobval()
into my_clob
from dual;

【讨论】:

以上是关于读取 XML 格式的字符串并使用 PL SQL 中的 for 循环进行更新的主要内容,如果未能解决你的问题,请参考以下文章