您可以使用 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<>小提琴