Home > Blockchain >  add a an extra row in the outcome
add a an extra row in the outcome

Time:04-07

I have a ORACLE sql query that needs to add a header (Only one row) with the name of the columns in the outcome. How could that be achieved?

1-1-2022 08:32:00   xxx1    166 1   04641127    8   1
1-1-2022 07:05:00   xxx1    167 1   10205792    8   1
1-1-2022 09:20:00   xxx1    176 1   10256841    8   1
1-1-2022 10:10:00   xxx1    177 1   10193856    8   1

Regards

Date                dep    room nr   rec       type count
6-4-2022 08:32:00   xxx1    166 1   04641127    8   1
6-4-2022 07:05:00   xxx1    167 1   10205792    8   1
5-4-2022 09:20:00   xxx2    176 1   10256841    8   1
5-4-2022 10:10:00   xxx2    177 1   10193856    8   1

CodePudding user response:

UNION is one option; note that - in that case - both SELECT statements have to share the same number of columns and their datatypes.

Something like this:

select 'Date' col1, 'dep' col2, 'room' col3, 'nr' col4, 'rec' col5, 'type' col6, 'count' col7
from dual
union all
select to_char(date_column, 'dd-mm-yyyy hh24:mi:ss'), 
  dep, 
  to_char(room), 
  to_char(nr),
  rec,
  to_char(type), 
  to_char(count_column)
from some_table
  • Related