我有一个包含XMLType字段的表。使用以下DDL / DML创建和加载表:
CREATE TABLE T_ECO_test_LOG
(
SECID NUMBER NOT NULL,
LOG_ATTRIBUTES SYS.XMLTYPE
)
INSERT INTO t_eco_test_log VALUES
( 1, XMLType(
'<attributes>
<attribute>
<name>remoteAddress</name>
<value>180.201.106.130</value>
</attribute>
<attribute>
<name>domain</name>
<value>BSI_US</value>
</attribute>
</attributes>'));
INSERT INTO t_eco_test_log VALUES
( 2, XMLType(
'<attributes>
<attribute>
<name>user</name>
<value>xxxx</value>
</attribute>
<attribute>
<name>domain</name>
<value>BSI_US</value>
</attribute>
</attributes>'));
我想在/ attributes / attribute / name中获取行中的不同值;所以有了数据O想得到:
remoteAddress
domain
user
到目前为止,我已尝试过以下查询:
select extractValue(value(x),'/attributes/attribute/name')
from t_eco_log,
table(xmlsequence(extract(log_attributes,'/attributes')) )x
但我收到以下消息:
ORA-19025:EXTRACTVALUE只返回一个节点的值
如果我使用
select extract(value(x),'/attributes/attribute/name')
from t_eco_log,
table(xmlsequence(extract(log_attributes,'/attributes')) )x
我得到的XML结果包含:
<name>remoteAddress</name><name>domain</name>
但我想把它们作为行,我该怎么做?
TIA
答案 0 :(得分:2)
类似的东西:
with x1 as (select xmltype('<attributes>
<attribute>
<name>remoteAddress</name>
<value>180.201.106.130</value>
</attribute>
<attribute>
<name>domain</name>
<value>BSI_US</value>
</attribute>
</attributes>') x2 from dual)
select extract(value(x3),'/attribute/name')
from x1,
table(xmlsequence(extract(x2,'/attributes/*')) ) x3
如果提供CREATE TABLE和INSERT,则更容易提供精确的SQL
答案 1 :(得分:0)
我明白了。基于加里所说的:
with x1 as (select log_attributes x2 from t_eco_test_log)
select distinct(extractValue(value(x3),'/attribute/name'))
from x1,
table(xmlsequence(extract(x2,'/attributes/*')) ) x3
谢谢!