I want to concat to the output based on condition. Here is my query:
select 'hey',
case id =1 then 'Mary' else 'Tom' end
from names;'
I want to print 'hey tom' or 'hey mary' based on id ... any help ??
It is concatenation you need; in Oracle, double pipe || represents that operator:
SQL> with names (id) as
2 (select 1 from dual union all
3 select 2 from dual union all
4 select 3 from dual
5 )
6 select id,
7 'hey ' || case when id = 1 then 'Mary'
8 else 'Tom'
9 end result
10 from names;
ID RESULT
---------- ----------
1 hey Mary
2 hey Tom
3 hey Tom
SQL>
dual is a built-in Oracle table that's frequently used for generating sample data. docs.oracle.com/cd/B19306_01/server.102/b14200/queries009.htm