3

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は1つのノードのみの値を返します

私が使用する場合

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>

しかし、それらを行として取得したいのですが、どうすればよいですか?

ティア

4

2 に答える 2

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 を簡単に指定できます。

于 2010-11-07T22:24:35.663 に答える
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

ありがとうございました!

于 2010-11-07T23:57:43.220 に答える