我正在嘗試在我的 oracle DB 中決議 xml 以回傳單個行。xml 是我的表中名為 msg 的欄位 Sample xml is
<application xmlns="http://www.abcxyz.com/Schema/FCX/1"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
<client>
<clientSource>
<amount>25000.0</amount>
<clientSourceTypeDd>1</clientSourceTypeDd>
<description>aasdadsf</description>
</clientSource>
<clientSource>
<amount>25000.0</amount>
<clientSourceType>6</clientSourceTypeDd>
<description>wrewertwerewrt</description>
</clientSource>
<clientSource>
<amount>50000.0</amount>
<clientSourceType>10</clientSourceTypeDd>
<description>second and thirs</description>
</clientSource>
</client>
</application>
我已經嘗試了以下查詢,但沒有按預期作業
SELECT EXTRACT(t.msg, '//application/client/clientSource[*]/clientSourceType/text()')
.getStringVal() clientSourceType,
EXTRACT(t.msg, '/pplication/client/clientSource/amount')
.getStringVal() clientSourceAmount
FROM table t
我想要達到的預期結果是
| 客戶來源型別 | 客戶來源金額 |
|---|---|
| 1 | 25000 |
| 6 | 25000 |
| 10 | 50000 |
請幫助解決,因為我是決議 xml 和 oracle 的新手。謝謝
uj5u.com熱心網友回復:
您可以使用XMLTABLEOracle 推薦的而不是棄用的函式EXTRACTVALUE,在通過轉換clientSourceTypeDd為固定標記名稱之后clientSourceType,以使開始和結束標記名稱匹配,例如
WITH t( xml ) AS
(
SELECT XMLType('<application xmlns="http://www.abcxyz.com/Schema/FCX/1"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
<client>
<clientSource>
<amount>25000.0</amount>
<clientSourceType>1</clientSourceType>
<description>aasdadsf</description>
</clientSource>
<clientSource>
<amount>25000.0</amount>
<clientSourceType>6</clientSourceType>
<description>wrewertwerewrt</description>
</clientSource>
<clientSource>
<amount>50000.0</amount>
<clientSourceType>10</clientSourceType>
<description>second and thirs</description>
</clientSource>
</client>
</application>')
FROM dual
)
SELECT "clientSourceType", "clientSourceAmount"
FROM t,
XMLTABLE( XMLNAMESPACES( DEFAULT 'http://www.abcxyz.com/Schema/FCX/1' ),
'/application/client/clientSource'
PASSING xml
COLUMNS
"clientSourceType" INT PATH 'clientSourceType',
"clientSourceAmount" INT PATH 'amount'
)
| 客戶來源型別 | 客戶來源金額 |
|---|---|
| 1 | 25000 |
| 6 | 25000 |
| 10 | 50000 |
Demo
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/448726.html
標籤:sql xml 甲骨文 oracle11g xml 解析
上一篇:SQl-相交,需要表1中的更多列
下一篇:Apex上的圖表過濾器
