我根据视图运行此xml查询:(oracle 11g r1)
select xmlelement("clientid", xmlattributes (a.clientid),
(select xmlagg(
xmlelement("plan",
xmlattributes(b.planid,b.planame),
xmlagg( xmlelement ("ppt", xmlattributes ( b.pname, b.pdname)
)))) from **viewname** b
where b.clientid = a.clientid
group by b.planid,b.planname)) as xmlfrom **viewname** a group by a.clientid;
是否可以针对xmlsequence(游标)而不是视图运行此命令?即。
select xmlelement("clientid", xmlattributes (a.clientid),
(select xmlagg(
xmlelement("plan",
xmlattributes(b.planid,b.planame),
xmlagg( xmlelement ("ppt", xmlattributes ( b.pname, b.pdname)
)))) from **table(xmlsequence(cursor))** b
where b.clientid = a.clientid
group by b.planid,b.planname)) as xml from **table(xmlsequence(cursor))** a group by a.clientid;
还是有其他办法吗? 我的oracle xml的东西真的很缺乏,所以如果我的问题是newb-ish,我道歉... 感谢
答案 0 :(得分:0)
我不确定这是否是一个解决方案,但如果我想制作一个xml我就像这样做:
我正在声明游标:
CURSOR cur(l_date_od date, l_date_do date) IS
select ... from .. where ...;
我正在声明游标行类型
variable cur%ROWTYPE;
每行选择xml_type变量
open cur(local_date1,local_date2);
loop
fetch linia into variable ;
exit when cur%NOTFOUND;
select xmlelement("ROW",
xmlelement("VENDOR_SITE_CODE",variable .VENDOR_SITE_CODE ),
xmlelement("ATTRIBUTE1",variable .ATTRIBUTE1 ),
xmlelement("INVOICE_NUM",variable .INVOICE_NUM ),
xmlelement("INVOICE_DATE",variable .INVOICE_DATE )
)
into xml_type_variable
FROM dual;
xml_file2 :=(xml_file.getClobVal()); ----Here i am conversing to clob
end loop;
close linia;