数据库

 首页 > 数据库 > Oracle > Oracle函数wmsys.wm_concat的使用

Oracle函数wmsys.wm_concat的使用

分享到:
【字体:
导读:
         摘要:首先介绍语法:wmsys.wm_concatDefinition:TheOraclePL/SQLWM_CONCATfunctionisusedtoaggregatedatafromanumberofrowsintoasinglerow,givingalistofdataassoci... ...

Oracle函数wmsys.wm_concat的使用

首先介绍语法:
wmsys.wm_concat
 
Definition:
The Oracle PL/SQL WM_CONCAT function is used to aggregate data from a number of rows into a single row, giving a list of data associated with a specific value. In effect, it cross-tabulates a comma delimited list.
  www.2cto.com  
Note that WM_CONCAT is undocumented and unsupported by Oracle, meaning it should not be used in production systems. The LISTAGG function, which can produce the same output asWM_CONCAT is both documented and supported by Oracle.
 
例子:
[sql]
select t1.main_id,  
       to_char(wmsys.wm_concat(t1.send_id || '||' || t2.realname || '||' ||  
                               t2.IMG_PATH)) sendidlist  
  from LCMS_SEND_USER t1, LCMS_USER_STUD t2  
 group by t1.main_id;  
 
结果:
 
 
网络中也有这样使用:
 
下面只是收藏:
 
[sql]
SQL> select id,wmsys.wm_concat(name) over (order by id) name from idtable;  
    www.2cto.com  
        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]
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  
    www.2cto.com  
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;  
    www.2cto.com  
        ID NAME  
---------- --------------------------------------------------------------------------------  
        10 ab  
        10 bc  
        10 cd  
        20 hi  
        20 ij  
        20 mn  
  
6 rows selected  
 
 
 
作者 psyuhen
Oracle函数wmsys.wm_concat的使用
分享到:
Oracle对2位年份的处理简析
Oracle对2位年份的处理简析 虽然Oracle数据存储了4位的年份,但是如果只提供2位数字,Oracle就会根据使用的格式是YY还是RR来解释世纪。 YY格式 如果日期中的年份采用的格式为YY,并且只提供了2位年份,那么就认为这一年世纪与数据库服务器上当前设置的世纪相同。因此,指定年份的前两位数字与前年份的前两位数据字相同。例...
centos 6.2上oracle 11g的远程安装
centos 6.2上oracle 11g的远程安装 版本号: 11g   端口:1521   安装文件:/install/ linux.x64_11gR2_database_1of2.zip, linux.x64_11gR2_database_2of2.zip   www.2cto.com   安装过程:此次安装以centos没装图形界面,使用远程安装。   使用工具:ssh+xmanager,我用的xmanager是4.0   打开xmanager-passive模式...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……