Home > Enterprise >  How to add timestaps columns numeric columns as an hour
How to add timestaps columns numeric columns as an hour

Time:12-21

I have to following table called my_table.

| date                     |numeric_data| new_date
|: -------- |: --------------:|:
| 2019-04-16 00:00:00.0    | 11         |2019-04-16 11:00:00.0 
| 2019-04-15 00:00:00.0    | 13         |2019-04-16 13:00:00.0 
select date  interval to_char(numeric_data) hour from my_table

but it does not works

CodePudding user response:

You can use the NUMTODSINTERVAL function:

SELECT date_column   NUMTODSINTERVAL(numeric_data, 'HOUR') AS new_date
FROM   my_table

or you can add a multiple of INTERVAL '1' HOUR:

SELECT date_column   numeric_data * INTERVAL '1' HOUR AS new_date
FROM   my_table

or you can add fractions of days:

SELECT date_column   numeric_data/24 AS new_date
FROM   my_table

Which, for the sample data:

CREATE TABLE my_table ( date_column, numeric_data ) AS
SELECT DATE '2019-04-16', 11 FROM DUAL UNION ALL
SELECT DATE '2019-04-15', 13 FROM DUAL;

All output:

NEW_DATE
2019-04-16T11:00:00
2019-04-15T13:00:00

fiddle

  • Related