在 XMLType 上选择不同的值
我有一个包含 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
I've got a table that has a XMLType field. The table is created and loaded using the following 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>'));
I want to get the different values in /attributes/attribute/name, in rows; So with data O would like to get:
remoteAddress
domain
user
So far I've tried the following query:
select extractValue(value(x),'/attributes/attribute/name')
from t_eco_log,
table(xmlsequence(extract(log_attributes,'/attributes')) )x
But I get the following message :
ORA-19025: EXTRACTVALUE returns value of only one node
If I use
select extract(value(x),'/attributes/attribute/name')
from t_eco_log,
table(xmlsequence(extract(log_attributes,'/attributes')) )x
I got a XML result which contains :
<name>remoteAddress</name><name>domain</name>
But I would like to get them as rows, how can I do that?
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
类似于:
如果你提供 CREATE TABLE 和 INSERT,那么更容易给出精确的 SQL
Something like :
If you supply CREATE TABLE and INSERT, then it is easier to give a precise SQL
我得到了它。根据加里所说:
谢谢!
I got it. Base on what Gary put:
Thank you!