• ORACLE 多列合并成一行数据 WM_CONCAT函数以及REPLACE


    WM_CONCAT()方法 注意字符长度

    SELECT BERTHCODE,tpf.freedatetype,
    ( SELECT  WM_CONCAT(SBPT.PARKSTIME||'~'||SBPT.PARKETIME) SAREE FROM  
    SYS_BERTHANDTYPE SBT LEFT JOIN  SYS_BERTHTYPEPARKTIME SBPT  
    ON SBT.BERTHTYPEID = SBPT.BERTHTYPEID WHERE BERTHCODE='114163' AND 
     SBPT.DATETYPE = 1 AND  SBPT.ISALLOW = 2)  
     NOTALLOWTIMESPAN, WM_CONCAT(SUBSTR(TO_CHAR(FREESTARTTIME,'YYYY-MM-DD HH24:MI:SS'),11,9)||'~'||SUBSTR(TO_CHAR(FREEENDTIME,'YYYY-MM-DD HH24:MI:SS'),11,9)) 
    FREETIMESPAN
    FROM TRA_PRICINGBERTH TPB LEFT JOIN TRA_PRICINGFREE TPF ON TPB.PRICINGSTRATEGYID = TPF.PRICINGSTRATEGYID WHERE BERTHCODE='114163' AND FREEDATETYPE=1 GROUP BY BERTHCODE,tpf.freedatetype order by BERTHCODE

     可以使用以下这个方法REPLACE(WM_CONCAT())


    SELECT TPB.BERTHCODE, ( SELECT REPLACE(WM_CONCAT(SBPT.PARKSTIME||'~'||SBPT.PARKETIME)OVER (PARTITION BY BERTHCODE,SBPT.PARKETIME), ',', ';') AS SAREE FROM SYS_BERTHANDTYPE SBT LEFT JOIN SYS_BERTHTYPEPARKTIME SBPT ON SBT.BERTHTYPEID = SBPT.BERTHTYPEID WHERE SBT.BERTHCODE='114163' AND SBPT.DATETYPE = 1 AND SBPT.ISALLOW =2 ) AS NOTALLOWTIMESPAN ,
    REPLACE(WM_CONCAT(SUBSTR(TO_CHAR(FREESTARTTIME,'YYYY-MM-DD HH24:MI:SS'),11,9) ||'~'||SUBSTR(TO_CHAR(FREEENDTIME,'YYYY-MM-DD HH24:MI:SS'),11,9)), ',', ';') AS FREETIMESPAN FROM TRA_PRICINGBERTH TPB LEFT JOIN TRA_PRICINGFREE TPF ON TPB.PRICINGSTRATEGYID = TPF.PRICINGSTRATEGYID WHERE TPB.BERTHCODE='114163' AND TPF.FREEDATETYPE=1 GROUP BY BERTHCODE

    如果遇到版本问题 在Oracle11G下可以使用以下方法 LISTAGG()

    SELECT  TPB.BERTHCODE, ( SELECT  LISTAGG( (SBPT.PARKSTIME||'~'||SBPT.PARKETIME), '; ' ) WITHIN GROUP (ORDER BY SBPT.PARKTIMEID)
     AS SAREE  FROM SYS_BERTHANDTYPE SBT
    LEFT JOIN  SYS_BERTHTYPEPARKTIME SBPT ON SBT.BERTHTYPEID = SBPT.BERTHTYPEID 
          WHERE SBT.BERTHCODE='114163' AND  SBPT.DATETYPE = 1 AND  SBPT.ISALLOW =2
          ) AS NOTALLOWTIMESPAN ,
          LISTAGG(SUBSTR(TO_CHAR(FREESTARTTIME,'YYYY-MM-DD HH24:MI:SS'),11,9)
           ||'~'||SUBSTR(TO_CHAR(FREEENDTIME,'YYYY-MM-DD HH24:MI:SS'),11,9), '; ')WITHIN GROUP (ORDER BY TPF.FREEID)
           AS  FREETIMESPAN       
           FROM TRA_PRICINGBERTH  TPB 
           LEFT JOIN TRA_PRICINGFREE TPF  ON TPB.PRICINGSTRATEGYID = TPF.PRICINGSTRATEGYID 
          WHERE 
         TPB.BERTHCODE='114163'  
        AND TPF.FREEDATETYPE=1  
          GROUP BY BERTHCODE

    WM_CONCAT 合并成一行数据列 数据量大会超出字符长度

    SELECT wm_concat(sbpt.ParkStime||'~'||sbpt.ParkEtime) FROM SYS_BerthTypeParkTime sbpt

    REPLACE 分成多列
    SELECT  REPLACE(sbpt.ParkStime||'~'||sbpt.ParkEtime,',')
     FROM SYS_BerthTypeParkTime sbpt

  • 相关阅读:
    MFC之绘制线条
    CDC类详解
    MFC之消息映射机制实现方法
    VS2008如何自动添加消息映射
    MFC框架程序剖析
    Visual Assist 相同内容高亮显示
    Win32 Console Application、Win32 Application、MFC三者之间的联系和区别
    win32应用程序创建流程
    BigDecimal最基础用法【转】
    html 高亮显示表格当前行【转】
  • 原文地址:https://www.cnblogs.com/Warmsunshine/p/4148316.html
Copyright © 2020-2023  润新知