0

我在 Oracle 11g 中有下表:

         CREATE TABLE jason_xml(
            id    NUMBER(5) PRIMARY KEY,
            xml_content XMLTYPE
         )tablespace WD_T

在 xml_content 列中,我有一个 XML 文档:

     <results>
<return>
    <actualtime>0.0</actualtime>
    <billingamount>0.0</billingamount>
    <buildlisttext>
        <buildnumber>0</buildnumber>
        <completiondate>2007-04-10T12:36:00+02:00</completiondate>
        <componentid>0</componentid>
        <containsrecipients>false</containsrecipients>
        <containsrecipientshasbeenset>true</containsrecipientshasbeenset>
        <costamount>0.0</costamount>
        <createdate>2006-11-20T17:10:02+01:00</createdate>
        <createdbysystemuserid>89198</createdbysystemuserid>
        <currentownersystemuserid>12122</currentownersystemuserid>
        <currentownerusergroupid>0</currentownerusergroupid>
        <customerid>95</customerid>
        <description>From: Ricky Bolton</description> 
    </buildlisttext>
</return>
<return>
    <actualtime>0.0</actualtime>
    <billingamount>0.0</billingamount>
    <buildlisttext>
        <buildnumber>0</buildnumber>
        <completiondate>2007-04-10T12:36:00+02:00</completiondate>
        <componentid>0</componentid>
        <containsrecipients>false</containsrecipients>
        <containsrecipientshasbeenset>true</containsrecipientshasbeenset>
        <costamount>0.0</costamount>
        <createdate>2006-11-20T17:10:02+01:00</createdate>
        <createdbysystemuserid>89198</createdbysystemuserid>
        <currentownersystemuserid>12122</currentownersystemuserid>
        <currentownerusergroupid>0</currentownerusergroupid>
        <customerid>95</customerid>
        <description>From: Derek Trotter</description> 
    </buildlisttext>
</return>
    </results>

我正在尝试从我的 jason_xml 表列中查询此文档,然后将结果显示为:

        |billingamount|Description|
        |0.0          |From: Ricky Bolton|
        |0.0          |From: Derek Trotter|

我一直在指出 Oracle API 的方向,但我不太擅长阅读 API,并且发现这个 API 写得非常糟糕。我已经尝试了这个页面上定义的一些运算符,但没有任何乐趣:

http://docs.oracle.com/cd/B28359_01/appdev.111/b28369/xdb04cre.htm#BABDGFFH

我已经做到了这一点,但在 PL/SQL 开发人员中不断收到“无效标识符”。我知道我可能完全错了,所以有人有任何指示/解决方案吗?

     SELECT extractValue(OBJECT_VALUE, 'results/return/buildlisttext/description') "DESCRIPTION" FROM jason_xml x WHERE xmlexists('results/return/buildlisttext/description' PASSING OBJECT_VALUE);

我正在使用带有 PHP 的 MySQL 用户,并且可以通过这种技术组合轻松地做到这一点,但不幸的是我必须在工作中使用 Oracle 11g。

任何帮助将不胜感激。

4

2 回答 2

1

事实证明,这是针对这种情况的正确响应:

              SELECT xtab.billingamount, xtab.description
              FROM jason_xml jx, xmltable('/results/return' 
              PASSING jx.xml_content 
              COLUMNS billingamount varchar2(4000) path '//billingAmount', 
                      description clob path '//description'
                      )xtab;
于 2013-08-07T08:58:50.853 回答
0

试试这个。可能有更简单的方法。

SELECT EXTRACTVALUE (t.COLUMN_VALUE, 'return/billingamount') Billing_Amount,
       EXTRACTVALUE (t.COLUMN_VALUE, 'return/buildlisttext/description') Description
  FROM jason_xml,
       XMLTABLE ('for $i in /results/return return $i'
                 PASSING jason_xml.xml_content) t

这是SQL Fiddle 示例

这不包括您显示的约束,但您可以轻松地将其添加到 XQuery 表达式中。

于 2013-08-07T01:11:34.260 回答