2010-11-07 50 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 

謝謝!