zoukankan      html  css  js  c++  java
  • oracle wmsys.wm_concat 函数用法

    oracle wmsys.wm_concat 函数,它的作用是以','链接字符。

    例子如下:

    SQL> create table idtable (id number,name varchar2(30));

    Table created

    SQL> insert into idtable values(10,'ab');

    1 row inserted

    SQL> insert into idtable values(10,'bc');

    1 row inserted

    SQL> insert into idtable values(10,'cd');

    1 row inserted

    SQL> insert into idtable values(20,'hi');

    1 row inserted

    SQL> insert into idtable values(20,'ij');

    1 row inserted
    SQL> insert into idtable values(20,'mn');

    1 row inserted

    SQL> select * from idtable;

            ID NAME
    ---------- ------------------------------
            10 ab
            10 bc
            10 cd
            20 hi
            20 ij
            20 mn

    6 rows selected
    SQL> select id,wmsys.wm_concat(name) name from idtable
      2  group by id;

            ID NAME
    ---------- --------------------------------------------------------------------------------
            10 ab,bc,cd
            20 hi,ij,mn

    SQL> select id,wmsys.wm_concat(name) over (order by id) name from idtable;

            ID NAME
    ---------- --------------------------------------------------------------------------------
            10 ab,bc,cd
            10 ab,bc,cd
            10 ab,bc,cd
            20 ab,bc,cd,hi,ij,mn
            20 ab,bc,cd,hi,ij,mn
            20 ab,bc,cd,hi,ij,mn

    6 rows selected

    SQL> select id,wmsys.wm_concat(name) over (order by id,name) name from idtable;

            ID NAME
    ---------- --------------------------------------------------------------------------------
            10 ab
            10 ab,bc
            10 ab,bc,cd
            20 ab,bc,cd,hi
            20 ab,bc,cd,hi,ij
            20 ab,bc,cd,hi,ij,mn

    6 rows selected

    个人觉得这个用法比较有趣.

    SQL> select id,wmsys.wm_concat(name) over (partition by id) name from idtable;

            ID NAME
    ---------- --------------------------------------------------------------------------------
            10 ab,bc,cd
            10 ab,bc,cd
            10 ab,bc,cd
            20 hi,ij,mn
            20 hi,ij,mn
            20 hi,ij,mn

    6 rows selected

    SQL> select id,wmsys.wm_concat(name) over (partition by id,name) name from idtable;

            ID NAME
    ---------- --------------------------------------------------------------------------------
            10 ab
            10 bc
            10 cd
            20 hi
            20 ij
            20 mn

    6 rows selected

  • 相关阅读:
    Git查询
    HDU-3038 How Many Answers Are Wrong 并查集
    CodeForcesEducationalRound40-D Fight Against Traffic 最短路
    HDU-6109 数据分割 并查集(维护根节点)
    ZOJ-3261 Connections in Galaxy War 并查集 离线操作
    AtCoderBeginner091-C 2D Plane 2N Points 模拟问题
    HDU-1878 欧拉回路 欧拉回路
    [笔记-图论]Floyd
    [笔记-图论]Bellman-Ford
    [笔记-图论]Dijkstra
  • 原文地址:https://www.cnblogs.com/leonsky/p/2703539.html
Copyright © 2011-2022 走看看