2012-11-28 96 views
2

我有一個像如何在一列用分隔符組合兩個列結果

select a.host_coll_code AS "Code", a.description AS "DESCRIPTION" 
from coll_collateral a 

當此查詢運行我得到的結果是這樣的

Code   DESCRIPTION 
    --------------------------- 
    123    ABC 
    589    UYR 
    ...    ... 

我想要得到的結果查詢在一列中帶有分隔符

Code and Description 
--------------------- 
     123-ABC 
     589-UYR 
     .... 

我該怎麼辦?

感謝

回答

2

通過使用concat函數或串聯運算符||

SQL> with t1(Code, DESCRIPTION) as(
    2 select 123, 'ABC' from dual union all 
    3 select 589, 'UYR' from dual 
    4 ) 
    5 select concat(concat(to_char(code), '-'), DESCRIPTION) result 
    6 from t1 
    7 ; 

RESULT 
----------- 
123-ABC 
589-UYR 

OR

select to_char(code) || '-' || Description result 
    from t1 

RESULT 
----------- 
123-ABC 
589-UYR 
1
select a.host_coll_code || '-' || a.description AS "Code and Description" 
from coll_collateral a 
1
select CAST(a.host_coll_code AS VARCHAR(100)) 
     ||'-'|| 
     a.description AS "CODE_AND_DESCRIPTION" 
from coll_collateral a 
相關問題