How to combine two column results in a column with a separator

advertisements

I have a query like

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

When this query runs I get result something like this

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

I want to get the result in one column with a separator like

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

How can I do it ?

Thanks


By using concat function or concatenation operator ||:

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