簡體   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