我有一个像
这样的查询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
....
我该怎么做?
由于
答案 0 :(得分: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 :(得分:1)
select a.host_coll_code || '-' || a.description AS "Code and Description"
from coll_collateral a
答案 2 :(得分:1)
select CAST(a.host_coll_code AS VARCHAR(100))
||'-'||
a.description AS "CODE_AND_DESCRIPTION"
from coll_collateral a