Skip to main content
TopMiniSite

Back to all posts

How to Convert Decimal to Time In Oracle Sql?

Published on
3 min read
How to Convert Decimal to Time In Oracle Sql? image

Best Oracle SQL Conversion Tools to Buy in October 2025

1 Oracle 12c: SQL

Oracle 12c: SQL

BUY & SAVE
$58.01 $128.95
Save 55%
Oracle 12c: SQL
2 OCE Oracle Database SQL Certified Expert Exam Guide (Exam 1Z0-047) (Oracle Press)

OCE Oracle Database SQL Certified Expert Exam Guide (Exam 1Z0-047) (Oracle Press)

BUY & SAVE
$59.41 $68.00
Save 13%
OCE Oracle Database SQL Certified Expert Exam Guide (Exam 1Z0-047) (Oracle Press)
3 Murach's Oracle SQL and PL/SQL for Developers

Murach's Oracle SQL and PL/SQL for Developers

BUY & SAVE
$42.27 $54.50
Save 22%
Murach's Oracle SQL and PL/SQL for Developers
4 Easy Oracle PLSQL Programming: Get Started Fast with Working PL/SQL Code Examples (Easy Oracle Series)

Easy Oracle PLSQL Programming: Get Started Fast with Working PL/SQL Code Examples (Easy Oracle Series)

BUY & SAVE
$27.25
Easy Oracle PLSQL Programming: Get Started Fast with Working PL/SQL Code Examples (Easy Oracle Series)
5 Oracle PL/SQL Best Practices: Write the Best PL/SQL Code of Your Life

Oracle PL/SQL Best Practices: Write the Best PL/SQL Code of Your Life

  • AFFORDABLE PRICING FOR QUALITY USED BOOKS IN GOOD CONDITION.
  • ECO-FRIENDLY CHOICE: GIVE BOOKS A NEW LIFE AND SAVE THE PLANET.
  • DIVERSE SELECTION: FIND HIDDEN GEMS ACROSS VARIOUS GENRES TODAY!
BUY & SAVE
$14.27 $29.99
Save 52%
Oracle PL/SQL Best Practices: Write the Best PL/SQL Code of Your Life
6 SQL Pocket Guide: A Guide to SQL Usage

SQL Pocket Guide: A Guide to SQL Usage

BUY & SAVE
$23.73 $35.99
Save 34%
SQL Pocket Guide: A Guide to SQL Usage
7 Oracle SQL Developer 2.1

Oracle SQL Developer 2.1

BUY & SAVE
$38.05 $60.99
Save 38%
Oracle SQL Developer 2.1
8 Study Guide for 1Z0-071: Oracle Database 12c SQL: Oracle Certification Prep

Study Guide for 1Z0-071: Oracle Database 12c SQL: Oracle Certification Prep

BUY & SAVE
$14.23 $14.99
Save 5%
Study Guide for 1Z0-071: Oracle Database 12c SQL: Oracle Certification Prep
9 A Guide to SQL

A Guide to SQL

BUY & SAVE
$73.41 $120.95
Save 39%
A Guide to SQL
10 Learn SQL By Examples: Examples of SQL Queries and Stored Procedures for MySQL and Oracle Databases

Learn SQL By Examples: Examples of SQL Queries and Stored Procedures for MySQL and Oracle Databases

BUY & SAVE
$4.99
Learn SQL By Examples: Examples of SQL Queries and Stored Procedures for MySQL and Oracle Databases
+
ONE MORE?

To convert decimal numbers to time in Oracle SQL, you can use the following steps:

  • First, multiply the decimal number by 24 to convert it to a 24-hour format.
  • Next, extract the hour part by using the TRUNC function.
  • Then, calculate the minute part by multiplying the remaining decimal part by 60 and extracting the integer value.
  • Finally, concatenate the hour and minute parts together to get the time in HH:MM format.

What is the significance of converting decimal to time in Oracle SQL queries?

Converting decimal numbers to time in Oracle SQL queries is significant because it allows for easier manipulation and display of time-related data. By converting decimal numbers to time, users can more easily understand and work with time values in their queries.

For example, if a decimal number represents a time duration (such as 1.5 hours), converting it to a time value allows users to perform calculations, comparisons, and formatting with that time value more easily. This can be particularly useful in applications where time calculations and scheduling are important.

Overall, converting decimal numbers to time in Oracle SQL queries enhances the usability and readability of time-related data, making it easier for users to work with and analyze time values in their databases.

How to calculate time duration from decimal values in Oracle SQL?

You can calculate the time duration from decimal values in Oracle SQL by first converting the decimal value to a TIMESTAMP data type, and then using the EXTRACT function to extract the hours, minutes, and seconds components from the TIMESTAMP value.

Here is an example query that demonstrates how to calculate the time duration from a decimal value in Oracle SQL:

SELECT TO_TIMESTAMP('1970-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS') + (your_decimal_value * INTERVAL '1' HOUR) AS start_time, TO_TIMESTAMP('1970-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS') + ((your_decimal_value + 1) * INTERVAL '1' HOUR) AS end_time, EXTRACT(HOUR FROM (TO_TIMESTAMP('1970-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS') + ((your_decimal_value + 1) * INTERVAL '1' HOUR')) - (TO_TIMESTAMP('1970-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS') + (your_decimal_value * INTERVAL '1' HOUR'))) AS duration_hours, EXTRACT(MINUTE FROM (TO_TIMESTAMP('1970-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS') + ((your_decimal_value + 1) * INTERVAL '1' HOUR')) - (TO_TIMESTAMP('1970-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS') + (your_decimal_value * INTERVAL '1' HOUR'))) AS duration_minutes, EXTRACT(SECOND FROM (TO_TIMESTAMP('1970-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS') + ((your_decimal_value + 1) * INTERVAL '1' HOUR')) - (TO_TIMESTAMP('1970-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS') + (your_decimal_value * INTERVAL '1' HOUR'))) AS duration_seconds FROM dual;

In this query, replace your_decimal_value with the actual decimal value you want to calculate the time duration for. The query will calculate the start time, end time, and the duration in hours, minutes, and seconds for the given decimal value.

Note: This calculation assumes that the decimal value represents a number of hours. If the decimal value represents a different unit of time, you may need to adjust the INTERVAL value accordingly.

One common approach for converting decimal numbers into time in Oracle SQL is to use the TO_DATE function along with date formatting to display the time in the desired format.

For example, if you have a decimal number representing hours (e.g. 2.5 hours) and you want to convert it to time (e.g. 02:30:00), you can use the following query:

SELECT TO_CHAR(TO_DATE((2.5 * 3600), 'SSSSS'), 'HH24:MI:SS') AS converted_time FROM dual;

In this query, 2.5 * 3600 converts the decimal number of hours to seconds, and then TO_DATE function converts the seconds to a date value. Finally, the TO_CHAR function is used to format the time as HH24:MI:SS.

This approach allows you to convert decimal numbers into time values in Oracle SQL.