Skip to content
Advertisement

How to convert decimal values to time values in oracle?

I have a table that is formatted like this:

I want the output to be like this:

Basically transform the values in the dec_time field into time values like the example above in new_dec_time.

This is my SQL so far:

This simply changes replaces the decimal point with the semicolon but doesnt add the 0s where needed. Is there a simple way to go about doing this? Any ideas or suggestions would help.

Advertisement

Answer

Never rely on default NLS settings if you need exact format. Always specify NLS parameters explicitly (for example, decimal separator in Russian is comma, not period).

So this is the query, if your numbers are restricted to valid time. If not, you’ll get nonsense that looks like time. Also Oracle have no time datatype alone, that’s why you need to implement operations with strings by yourself.

| TM     |
| :----- |
|  00:54 |
|  02:18 |
|  06:10 |

db<>fiddle here

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement