<root>
<note>
<id>1</id>
<text>公司</text>
<note>
</root>UPDATE t_trees set tree = updateXML(tree,'/root/note','<node><id>1</id><name>吉米</name><link>www.xx</link></node>') where existsnode(tree,'/root/node/id=1')=1 and ID=3;我想实现的是 把整个<note><id>1</id><text>公司</text><note> 更新为 <node><id>1</id><name>吉米</name><link>www.xx</link></node> 。。请问 这个语句 怎么写...上面我写了一个没作用!
<note>
<id>1</id>
<text>公司</text>
<note>
</root>UPDATE t_trees set tree = updateXML(tree,'/root/note','<node><id>1</id><name>吉米</name><link>www.xx</link></node>') where existsnode(tree,'/root/node/id=1')=1 and ID=3;我想实现的是 把整个<note><id>1</id><text>公司</text><note> 更新为 <node><id>1</id><name>吉米</name><link>www.xx</link></node> 。。请问 这个语句 怎么写...上面我写了一个没作用!
SQL> select * from t_xml_update;
ID NAME
----------- --------------------------------------------------------------------------------
1 <root>
<note>
<id>1</id>
<text>公司</text>
</note>
</root>
2 <root>
<note>
<id>2</id>
<text>公司</text>
</note>
</root>
SQL>
SQL> UPDATE t_xml_update
2 set name = updateXML(name,'/root/note','<node><id>1</id><name>吉米</name><link>www.xx</link></node>')
3 where existsnode(name,'/root/note/id=1')=1;
1 row updated
SQL> select * from t_xml_update;
ID NAME
----------- --------------------------------------------------------------------------------
1 <root>
<node>
<id>1</id>
<name>吉米</name>
<link>www.xx</link>
2 <root>
<note>
<id>2</id>
<text>公司</text>
</note>
</root>
SQL>
如果root 下有多个 node 而且其里面都有id元素...如果我想把id = 2 这个 更新掉...怎么加上这个条件?
SQL> select * from x;
ID TREE
----- -------------------------------------------------------------------------------
1 <root><node><id>1</id><id>2</id></node></root>
SQL> update x set tree=deletexml(tree,'/root/node/id[text()=2]') where id=1;
1 row updated
SQL> select * from x;
ID TREE
----- -------------------------------------------------------------------------------
1 <root><node><id>1</id></node></root>
UPDATE t
set tree = updateXML(tree,'/root/node[extractValue('/root/node/id=1')]','<node><id>1</id><name>是的</name><link>www.xx</link></node>')
报错
ORA-19039: Keyword string reserved for future use
Cause: The keyword is reserved for future use as a builtin function.
Action: Change the name mentioned above to a different one.
ID NAME
----------- --------------------------------------------------------------------------------
1 <root>
<node>
<id>1</id>
<name>吉米</name>
<link>www.xx</link>
SQL>
SQL> UPDATE t_xml_update
2 set name = updateXML(name,'/root/node','<node><id>1</id><name>是的</name><link>www.xx</link></node>')
3 where id=1;
1 row updated
SQL> select * from t_xml_update where id=1;
ID NAME
----------- --------------------------------------------------------------------------------
1 <root>
<node>
<id>1</id>
<name>是的</name>
<link>www.xx</link>
SQL>
SQL> select id,t.name.getstringval() from t_xml_update t where id=1;
ID T.NAME.GETSTRINGVAL()
----------- --------------------------------------------------------------------------------
1 <root>
<node>
<id>1</id>
<name>不是的</name>
<link>www.xyyx</link>
</node>
<node>
<id>2</id>
<name>3</name>
<link>4</link>
</node>
</root>
SQL>
SQL> UPDATE t_xml_update
2 set name = updateXML(name,'/root/node[id=1]','<node><id>1</id><name>no</name><link>www</link></node>')
3 where id=1;
1 row updated
SQL> select id,t.name.getstringval() from t_xml_update t where id=1;
ID T.NAME.GETSTRINGVAL()
----------- --------------------------------------------------------------------------------
1 <root>
<node>
<id>1</id>
<name>no</name>
<link>www</link>
</node>
<node>
<id>2</id>
<name>3</name>
<link>4</link>
</node>
</root>
SQL>