<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    新的起點 新的開始

    快樂生活 !

    列轉行 聚合的簡單實現 ORACLE WM_CONCAT LISTAGG 函數

    項目中有個需求,將關聯出來的數據以特定的字段將其他某一自動聚合。例子如下:

     

    1    B1
    1    B2
    1    B3
    2    B4
    2    B5
    3    B6

    to

     


    1    B1,B2,B3
    2    B4,B5
    3    B6

     

      拿到手就想到用存儲過程,其實還有更簡單的方式。那就是oracle 提供的字符串聚合函數。

     

    WM_CONCAT Built-in Function (Not Supported)

    If you are not running 11g Release 2, but are running a version of the database where the WM_CONCAT function is present, then it is a zero effort solution as it performs the aggregation for you. It is actually an example of a user defined aggregate function described below, but Oracle have done all the work for you.

     

    LISTAGG Analystic Function in 11g Release 2

    The LISTAGG analytic function was introduced in Oracle 11g Release 2, making it very easy to aggregate strings. The nice thing about this function is it also allows us to order the elements in the concatenated list. If you are using 11g Release 2 you should use this function for string aggregation.

     

    Example 如下:


    CREATE TABLE  "TESTAGG"
      (
        "A" VARCHAR2(20 BYTE),
        "B" VARCHAR2(20 BYTE)
      )


    INSERT INTO "TESTAGG" (A, B) VALUES ('1', 'B1')
    INSERT INTO "TESTAGG" (A, B) VALUES ('1', 'B2')
    INSERT INTO "TESTAGG" (A, B) VALUES ('1', 'B3')
    INSERT INTO "TESTAGG" (A, B) VALUES ('2', 'B4')
    INSERT INTO "TESTAGG" (A, B) VALUES ('2', 'B5')
    INSERT INTO "TESTAGG" (A, B) VALUES ('3', 'B6')

    select * from testAgg

    1    B1
    1    B2
    1    B3
    2    B4
    2    B5
    3    B6

    select  a  ,wm_concat (b) as policinams from testagg  group by a order by a

    select  a ,LISTAGG(b,',' ) within group(order by a) as b from testagg group by

    1    B1,B2,B3
    2    B4,B5
    3    B6

    posted on 2012-09-26 22:40 advincenting 閱讀(2510) 評論(0)  編輯  收藏 所屬分類: 數據庫相關

    公告

    Locations of visitors to this pageBlogJava
  • 首頁
  • 新隨筆
  • 聯系
  • 聚合
  • 管理
  • <2012年9月>
    2627282930311
    2345678
    9101112131415
    16171819202122
    23242526272829
    30123456

    統計

    常用鏈接

    留言簿(13)

    隨筆分類(71)

    隨筆檔案(179)

    文章檔案(13)

    新聞分類

    IT人的英語學習網站

    JAVA站點

    優秀個人博客鏈接

    官網學習站點

    生活工作站點

    最新隨筆

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 中文字字幕在线高清免费电影| WWW亚洲色大成网络.COM| 久9热免费精品视频在线观看| 久久久久国产免费| 亚洲日韩激情无码一区| 亚洲精品动漫人成3d在线| 亚洲综合无码AV一区二区| 亚洲精品国产va在线观看蜜芽| 亚洲欧美综合精品成人导航| 国产人成网在线播放VA免费| 国内精品免费麻豆网站91麻豆| 可以免费观看的一级毛片| 成人五级毛片免费播放| 青青青国产在线观看免费 | 无码人妻久久一区二区三区免费 | 一出一进一爽一粗一大视频免费的 | 手机看片久久国产免费| 国产精品美女自在线观看免费| 女人与禽交视频免费看| 亚洲欧洲日韩极速播放| 国产三级在线免费| 精品熟女少妇av免费久久| 国产一区二区三区免费看| 亚洲国产精品一区第二页| 亚洲高清一区二区三区电影| 精品国产无限资源免费观看| 国精无码欧精品亚洲一区| 中文字幕亚洲精品| 一区二区免费国产在线观看| 性做久久久久免费观看| 亚洲免费无码在线| 国产成人免费一区二区三区| 亚洲国产av一区二区三区丶| 13小箩利洗澡无码视频网站免费| 91精品国产免费久久国语蜜臀| 亚洲熟伦熟女新五十路熟妇| 国产亚洲精品AAAA片APP| 亚洲视频在线免费| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 亚洲第一视频网站| 亚洲va久久久久|