[英]xml response in pl/sql
with t as( select xmltype('< ROWSET>
< ROW>
< DEPTNO>10 < /DEPTNO>
< NAME>ACCOUNTING< /NAME>
< LOC>NEW YORK< /LOC>
< /ROW>
< ROW>
< DEPTNO>20< /DEPTNO>
< DNAME>RESEARCH< /DNAME>
< LOC>DALLAS< /LOC>
< /ROW>
< ROW>
< DEPTNO>30< /DEPTNO>
< DNAME>SALES</DNAME>
< LOC>CHICAGO < /LOC>
</ROW>
< ROW>
< DEPTNO>40< /DEPTNO>
< DNAME>OPERATIONS< /DNAME>
< LOC>BOSTON< /LOC>
< /ROW>
< /ROWSET>
') x from dual)
select extractvalue(t2.column_value,'ROW/DEPTNO') DEPTNO ,
extractvalue(t2.column_value,'ROW/DNAME') DNAME,
extractvalue(t2.column_value,'ROW/LOC') LOCATION
from t t, table(xmlsequence(t.x.extract('ROWSET/ROW'))) t2
Result: 结果:
DEPTNO DNAME LOCATION
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
But in my case the XML response is stored in a table in column of xmltype. 但是在我的情况下,XML响应存储在xmltype列的表中。 In which the same response which is there at the top is present in the xmltype column. 其中,xmltype列中存在顶部相同的响应。 so i used it as follows: 所以我用它如下:
with t as( select xml_doc x from xml_table where xml_name='EMPDETAILS' )
select extractvalue(t2.column_value,'ROW/DEPTNO') DEPTNO ,
extractvalue(t2.column_value,'ROW/DNAME') DNAME,
extractvalue(t2.column_value,'ROW/LOC') LOCATION
from t t, table(xmlsequence(t.x.extract('ROWSET/ROW'))) t2
It is not returning any rows. 它不返回任何行。 for which the same response is used in both the queries. 在两个查询中使用相同的响应。
Please let me know whether i need to change the way how i am using the second query. 请让我知道我是否需要更改使用第二个查询的方式。
Plz help...thanks in advance. 请帮助...提前感谢。
Unable to duplicate. 无法复制。 See code sample below: 请参见下面的代码示例:
Create table 建立表格
create table xml_table (
xml_name varchar2(100),
xml_doc xmltype
);
Insert data 插入资料
insert into xml_table (xml_name, xml_doc) values (
'EMPDETAILS',
xmltype('
<ROWSET>
<ROW>
<DEPTNO>10 </DEPTNO>
<NAME>ACCOUNTING</NAME>
<LOC>NEW YORK</LOC>
</ROW>
<ROW>
<DEPTNO>20</DEPTNO>
<DNAME>RESEARCH</DNAME>
<LOC>DALLAS</LOC>
</ROW>
<ROW>
<DEPTNO>30</DEPTNO>
<DNAME>SALES</DNAME>
<LOC>CHICAGO</LOC>
</ROW>
<ROW>
<DEPTNO>40</DEPTNO>
<DNAME>OPERATIONS</DNAME>
<LOC>BOSTON</LOC>
</ROW>
</ROWSET>
'));
insert into xml_table (xml_name, xml_doc) values (
'OTHERDETAILS',
xmltype('
<ROWSET>
<ROW>
<ELEMENT>HELIUM</ELEMENT>
</ROW>
</ROWSET>')
);
Query using table data 使用表数据查询
with t as( select xml_doc x from xml_table where xml_name='EMPDETAILS' )
select extractvalue(t2.column_value,'ROW/DEPTNO') DEPTNO ,
extractvalue(t2.column_value,'ROW/DNAME') DNAME,
extractvalue(t2.column_value,'ROW/LOC') LOCATION
from t t, table(xmlsequence(t.x.extract('ROWSET/ROW'))) t2;
Query using XMLType instance 使用XMLType实例查询
with t as( select xmltype('<ROWSET>
<ROW>
<DEPTNO>10 </DEPTNO>
<NAME>ACCOUNTING</NAME>
<LOC>NEW YORK</LOC>
</ROW>
<ROW>
<DEPTNO>20</DEPTNO>
<DNAME>RESEARCH</DNAME>
<LOC>DALLAS</LOC>
</ROW>
<ROW>
<DEPTNO>30</DEPTNO>
<DNAME>SALES</DNAME>
<LOC>CHICAGO </LOC>
</ROW>
<ROW>
<DEPTNO>40</DEPTNO>
<DNAME>OPERATIONS</DNAME>
<LOC>BOSTON</LOC>
</ROW>
</ROWSET>
') x from dual)
select extractvalue(t2.column_value,'ROW/DEPTNO') DEPTNO ,
extractvalue(t2.column_value,'ROW/DNAME') DNAME,
extractvalue(t2.column_value,'ROW/LOC') LOCATION
from t t, table(xmlsequence(t.x.extract('ROWSET/ROW'))) t2;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.