繁体   English   中英

dbms_xmlgen oracle获取动态xmltype

[英]dbms_xmlgen oracle get dynamic xmltype

我在oracle中有一个表t:

select op_id, dimorder, title from t:

OP_ID|DIMORDER|TITLE
-----+--------+-----
  312|       1|AAA
  312|       2|BBB

我想用dbms_xmlgen.getXml实现此结果(仅一行):

OP_ID|NEW_COLUMN
-----+----------
  312|<ROWSET><ROW><DIMORDER>1</DIMORDER><TITLE>AAA</TITLE>
       </ROW><ROW><DIMORDER>2</DIMORDER><TITLE>BBB</TITLE></ROW></ROWSET>

在此先感谢您的帮助

SQL / XML生成功能是从关系数据生成XML的首选方法。假设您有多组op_id行,则可以完成类似的工作。

 SQL>  set long 10000
 SQL> with MY_TABLE as
   2  (
   3     select 312 as op_id, 1 as dimorder, 'AAA' as title
   4        from dual
   5     union all
   6     select 312 as op_id, 2 as dimorder, 'BBB' as title
   7        from dual
   8     union all
   9     select 313 as op_id, 1 as dimorder, 'CCC' as title
  10        from dual
  11     union all
  12     select 313 as op_id, 2 as dimorder, 'DDD' as title
  13        from dual
  14  )
  15  select XMLELEMENT("ROWSET",
  16           XMLELEMENT("ROW",
  17             XMLAGG(
  18               XMLFOREST("DIMORDER" as DIMORDER, "TITLE" as TITLE)
  19               ORDER BY DIMORDER
  20             )
  21           )
  22         ) RESULT
  23    from MY_TABLE
  24   group by OP_ID
  25  /

 RESULT
 --------------------------------------------------------------------------------
 <ROWSET><ROW><DIMORDER>1</DIMORDER><TITLE>AAA</TITLE><DIMORDER>2</DIMORDER><TITLE>BBB</TITLE></ROW></ROWSET>

 <ROWSET><ROW><DIMORDER>1</DIMORDER><TITLE>CCC</TITLE><DIMORDER>2</DIMORDER><TITLE>DDD</TITLE></ROW></ROWSET>


 SQL>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM