我在 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。
任何帮助将不胜感激。