<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> 。。请问 这个语句 怎么写...上面我写了一个没作用!

解决方案 »

  1.   

    你写错xmlpath了..
    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> 
      

  2.   

    嗯。。好的. 你好.再问你些问题 
    如果root 下有多个 node  而且其里面都有id元素...如果我想把id = 2 这个 更新掉...怎么加上这个条件? 
      

  3.   

    UPDATE neew SET xtr = DELETEXML(xtr, '/Warehouse/Building/Owner') WHERE id = 22;我执行这个语句 报错这个...keyword deletexml reserved futrue for  user如我要删除 <node> 下 有<id> =2 的node  删除 ...如何写
      

  4.   


    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>
     
      

  5.   

    Oracle XML 不懂,进来学习的
      

  6.   

    我写一个这样的更新语句  有错误吗??
    UPDATE t
      set tree = updateXML(tree,'/root/node[extractValue('/root/node/id=1')]','<node><id>1</id><name>是的</name><link>www.xx</link></node>')
      

  7.   

    好像10g不支持deletexml...
    报错
    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.
      

  8.   

    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> 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> 
      

  9.   

    哦,看错,明白你啥意思了
    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>