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

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

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

    新的起點(diǎn) 新的開始

    快樂生活 !

    列轉(zhuǎn)行 聚合的簡(jiǎn)單實(shí)現(xiàn) ORACLE WM_CONCAT LISTAGG 函數(shù)

    項(xiàng)目中有個(gè)需求,將關(guān)聯(lián)出來(lái)的數(shù)據(jù)以特定的字段將其他某一自動(dòng)聚合。例子如下:

     

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

    to

     


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

     

      拿到手就想到用存儲(chǔ)過(guò)程,其實(shí)還有更簡(jiǎn)單的方式。那就是oracle 提供的字符串聚合函數(shù)。

     

    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 閱讀(2498) 評(píng)論(0)  編輯  收藏 所屬分類: 數(shù)據(jù)庫(kù)相關(guān)

    公告

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

    統(tǒng)計(jì)

    常用鏈接

    留言簿(13)

    隨筆分類(71)

    隨筆檔案(179)

    文章檔案(13)

    新聞分類

    IT人的英語(yǔ)學(xué)習(xí)網(wǎng)站

    JAVA站點(diǎn)

    優(yōu)秀個(gè)人博客鏈接

    官網(wǎng)學(xué)習(xí)站點(diǎn)

    生活工作站點(diǎn)

    最新隨筆

    搜索

    積分與排名

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 亚洲精品在线免费观看视频| 国产亚洲人成无码网在线观看 | 成年人免费网站在线观看| 亚洲人成电影网站色| 99久久亚洲综合精品成人网| 亚洲va中文字幕无码| 日韩一区二区a片免费观看| 中文字幕免费在线视频| 亚洲av无码成人影院一区| 亚洲精品电影天堂网| 亚洲avav天堂av在线不卡| 一本色道久久综合亚洲精品高清| 国产99精品一区二区三区免费| 亚洲中文字幕一区精品自拍| 亚洲a级片在线观看| 亚洲人和日本人jizz| 亚洲国产成人精品无码区在线网站| 亚洲色偷拍另类无码专区| 国产亚洲成人久久| 久久精品九九亚洲精品天堂| 亚洲成色www久久网站夜月| 亚洲国产精品成人久久| 久久久无码精品亚洲日韩按摩| 久久亚洲精品中文字幕无码| 亚洲尹人九九大色香蕉网站 | 999任你躁在线精品免费不卡| 少妇无码一区二区三区免费| 91久久成人免费| 永久中文字幕免费视频网站| 国产精品无码免费视频二三区 | g0g0人体全免费高清大胆视频| 97在线免费视频| 69成人免费视频无码专区| 国产18禁黄网站免费观看| 亚洲精品卡2卡3卡4卡5卡区| 亚洲黄色免费网址| 久久精品国产精品亚洲艾草网| 亚洲精品不卡视频| 一区二区视频免费观看| 亚洲三级高清免费| 在线成人爽a毛片免费软件|