Sql 连接列值

Sql 连接列值,sql,oracle11g,Sql,Oracle11g,我试图连接一列的值,但这些值必须格式化为另一个字符串 这是我的桌子: C1 C2 c3 c4 --------- --------- ------ -------- ID1 28-OCT-16 11.59.00 (null) 04-OCT-16 08.48.00 ID2 (nul

我试图连接一列的值,但这些值必须格式化为另一个字符串

这是我的桌子:

 C1         C2                      c3                  c4
---------   ---------               ------              --------
ID1         28-OCT-16 11.59.00      (null)              04-OCT-16 08.48.00
ID2         (null)                  05-OCT-16 02.55.00  (null)  
ID3         (null)                  10-OCT-16 04.32.00  21-OCT-16 02.25.00
ID4         10-OCT-16 04.32.00      18-OCT-16 08.52.00  18-OCT-16 08.32.00
ID5         10-OCT-16 04.32.00      (null)              (null)
我已经完成了设置表格格式以匹配所需的值

select 
    c1 T_ID,
    case when c2 is not null then 'Plane' end PLANE,
    case when c3 is not null then 'BUS' end BUS,
    case when c4 is not null then 'Hotel' end HOTEL
    from table1 
order by 1;




T_ID        PLANE                   BUS                 HOTEL
---------   ---------               ------              --------
ID1         Plane                   (null)              Hotel
ID2         (null)                  BUS                 (null)  
ID3         (null)                  BUS                 Hotel
ID4         Plane                   BUS                 Hotel
ID5         Plane                   (null)              (null)
我试着做以下几点

T_ID        SERVICE         
---------   ---------       
ID1         Plane+Hotel         
ID2         BUS         
ID3         BUS+Hotel           
ID4         Plane+BUS+Hotel         
ID5         Plane   

我尝试了几个串联函数,但找不到我想要的结果。

基本上可以执行以下操作:

select c1 T_ID,
       substr( (case when c2 is not null then '+Plane' end) ||
               (case when c3 is not null then '+BUS' end) ||
               (case when c4 is not null then '+Hotel' end)
               2)
from table1 
order by 1;

这基本上是通过将分隔符放在字符串中每个组件的开头来实现函数
concat_ws()
。外部
substr()
删除第一个字符。

“我尝试了几个串联函数”-您尝试了什么?什么不起作用?请告诉我们你想要的结果是什么