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
      ....

我该怎么做 ?

谢谢

4

3 回答 3

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

或者

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

 RESULT
-----------
123-ABC
589-UYR
于 2012-11-28T10:09:31.830 回答
1
select a.host_coll_code || '-' || a.description AS "Code and Description" 
from coll_collateral a 
于 2012-11-28T10:08:05.093 回答
1
select CAST(a.host_coll_code AS VARCHAR(100))
       ||'-'||
       a.description AS "CODE_AND_DESCRIPTION" 
from coll_collateral a
于 2012-11-28T10:08:38.313 回答