0

我有一个表 Transaction ,其中有一个 clob xclob ,

我想将“property”节点的“record_start_dll_date”值更新为record_start_date(即我想删除_dll部分)和“record_dll_end_date”更新为record_end_date。我正在使用 oracle 数据库。如何修改这些节点值?

<?xml version ="1.0"?>
<properties>
   <property name ="record_start_dll_date">
   <value>1/1/2021</value>
   </property>
    <property name ="record_dll_end_date">
   <value>21/12/2021</value>
   </property>
</properties>
4

1 回答 1

0

您可以使用 XMLQuery 更新,或者使用特定的属性值:

xmlquery ('copy $i := $p1 modify (
  (for $j in $i/properties/property[@name="record_start_dll_date"]/@name
    return replace value of node $j with $p2),
  (for $j in $i/properties/property[@name="record_dll_end_date"]/@name
    return replace value of node $j with $p3)
  ) return $i'
  passing xmltype(xclob) as "p1",
    'record_start_date' as "p2",
    'record_end_date' as "p3"
  returning content)

或剥离任何_dll

xmlquery ('copy $i := $p1 modify (
  for $j in $i/properties/property[contains(@name, "_dll")]/@name
    return replace value of node $j with replace($j, "_dll", "")
  ) return $i'
  passing xmltype(xclob) as "p1"
  returning content)

无论哪种方式,您都可以将其合并到更新语句中,并使用匹配的 XMLExists 子句来避免不必要的更新:

update transaction
set xclob = xmlquery ('copy $i := $p1 modify (
  for $j in $i/properties/property[contains(@name, "_dll")]/@name
    return replace value of node $j with replace($j, "_dll", "")
  ) return $i'
  passing xmltype(xclob) as "p1"
  returning content).getclobval()
where xmlexists('$p1/properties/property[contains(@name, "_dll")]'
  passing xmltype(xclob) as "p1")

db<>小提琴

于 2021-04-05T16:22:45.287 回答