问题描述
我有以下 XML:
我想根据一个简单的参数条件向这个 XML 添加一个额外的节点:
所需的输出:
代码:
我收到语法错误.任何帮助!
更新:
我在代码中实施了建议的解决方案,但出现以下错误.错过了一些愚蠢的东西!
我收到'XML 数据类型方法'修改'的错误使用.在这种情况下需要一个非突变方法.错误
不需要任何复杂的麻烦.只需根据需要插入所需的节点:
使用 as first
、as last
或 before/after
允许您指定节点的位置.下面将新节点直接放在
之后:
更新您关于更新语句的问题
你的陈述有几个缺陷:
<块引用>您不能使用语法 SET xmlColumn = xmlColumn.modify()
.您必须使用 SET xmlColumn.modify()
,而且分号无论如何都会破坏这一点.
老实说,我觉得这很复杂,试试这个:
这将创建一个新节点
,其中的内容从变量 @type
中取出.
I have the below XML:
I want to add an additional node to this XML based on a simple parametric condition:
desired output:
code:
I am getting syntax error. Any help!
UPDATE:
I implemented the suggested solution in my code and I'm getting below error. Missing out something silly!
I am getting 'Incorrect use of the XML data type method 'modify'. A non-mutator method is expected in this context.' error
No need for any complicated hassel. Just insert the node you want as you want it:
Using as first
, as last
or before / after
allows you to specify the node's position. The following will place the new node directly after <name>
:
UPDATE Your question about an update-statement
Your statement has several flaws:
You cannot use the syntax SET xmlColumn = xmlColumn.modify()
. You have to use SET xmlColumn.modify()
, Furthermore the semicolons are breaking this anyway.
To be honest, I think this is to complicated, try this:
This will create a new node <type>content</type>
, with a content taken out ot the variable @type
.
这篇关于使用 SQL 在 XML 中插入节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!