The way I understood the question, it is a matter of aggregation (listagg
, with pipe character as a separator):
SQL> with test (sample_column_data) as
2 (select 'SAM ANDREW' from dual union all
3 select 'JOHN MATHEW' from dual union all
4 select 'CHRIS JOE' from dual union all
5 select 'JANE PATRICK' from dual
6 )
7 select listagg(sample_column_data, '|') within group (order by null) result
8 from test;
RESULT
--------------------------------------------------------------------------------
CHRIS JOE|JANE PATRICK|JOHN MATHEW|SAM ANDREW
SQL>
If they have to be "true" separate columns, then you could use ROWNUM
with aggregation along with CASE
. This, of course, doesn't scale at all.
SQL> with test (sample_column_data) as
2 (select 'SAM ANDREW' from dual union all
3 select 'JOHN MATHEW' from dual union all
4 select 'CHRIS JOE' from dual union all
5 select 'JANE PATRICK' from dual
6 )
7 select
8 max(case when rownum = 1 then sample_column_data end) col1,
9 max(case when rownum = 2 then sample_column_data end) col2,
10 max(case when rownum = 3 then sample_column_data end) col3,
11 max(case when rownum = 4 then sample_column_data end) col4
12 from test;
COL1 COL2 COL3 COL4
------------ ------------ ---------- ------------
SAM ANDREW JOHN MATHEW CHRIS JOE JANE PATRICK
SQL>