2010-11-07 48 views
3

我有一个具有XMLType字段的表。该表中创建并使用下列DDL/DML加载的:在XMLType上选择不同的值

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>'));   

我想在/属性/属性/名称,行,以获得不同的值;因此,与数据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

回答

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

+0

我编辑了这个问题来澄清它,给出了一个表格和数据的例子,以及我想要得到的。谢谢你的帮助! – 2010-11-07 22:57:57

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 

谢谢!