我在Oracle 11g中見下表:選擇XML元素值並顯示多行的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|
我已經指出但是我不太擅長閱讀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的工作。
任何幫助將不勝感激。
這將返回81個空行... – jezzipin
你看SQLFiddle例子嗎?我用你提供的樣本數據運行它。 – OldProgrammer
我做到了。我在下面發佈的代碼是我設法正確工作的唯一代碼。 – jezzipin