相关的SQL语句如下:CREATE TABLE some_xml (x XMLType); /*建立XMLType表*/
INSERT INTO some_xml 
VALUES('<ManuInstructions ProductModelID="1" ProductModelName="SomeBike" >
<Location LocationID="L1" >
   <Step>Manu step 1 at Loc 1</Step>
   <Step>Manu step 2 at Loc 1</Step>
   <Step>Manu step 3 at Loc 1</Step>
</Location>
<Location LocationID="L2" >
   <Step>Manu step 1 at Loc 2</Step>
   <Step>Manu step 2 at Loc 2</Step>
   <Step>Manu step 3 at Loc 2</Step>
</Location>
</ManuInstructions>'); /*插入XML数据*/FLWOR表达式:$step in /ManuInstructions/Location[1] return string($step)
这个表达式是否有错?
请高手帮忙写一个SELECT语句在SQL*Plus中显示我要显示的内容,即:Manu step 1 at Loc 2Manu step 2 at Loc 2Manu step 3 at Loc 2

解决方案 »

  1.   


    select xmlquery('for $step in /ManuInstructions/Location[1]                 
                     return  string($step)'
                    passing x returning content) xml
    from some_xml ;XML                                                             
    ----------------------------------------------------------------
    Manu step 1 at Loc 1Manu step 2 at Loc 1Manu step 3 at Loc 1  
      

  2.   

    由结果可以看出是从1开始数的,如果想要你的结果要用select xmlquery('for $step in /ManuInstructions/Location[2]                 
                     return  string($step)'
                    passing x returning content) xml
    from some_xml;XML                                                             
    ----------------------------------------------------------------
    Manu step 1 at Loc 2Manu step 2 at Loc 2Manu step 3 at Loc 2   最好,改成按属性查找select xmlquery('for $step in /ManuInstructions/Location
                     where $step/@LocationID eq "L2"              
                     return  string($step)'
                    passing x returning content) xml
    from some_xml;XML                                                             
    ----------------------------------------------------------------
    Manu step 1 at Loc 2Manu step 2 at Loc 2Manu step 3 at Loc 2