Solved

Conversion of a number field in oracle sql

Posted on 2012-04-02
5
381 Views
Last Modified: 2012-04-02
Hi,

I am having a field which is a number(4) and it has values like
5000,-6000,-44,-56

I want it to be converted to
50:00
-60:00
-44:00
-56:00

Can this be done.

Please let me know.

Regards..
0
Comment
Question by:neoarwin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 8

Accepted Solution

by:
Christoffer Swanström earned 500 total points
ID: 37795571
What exactly would the logic for the conversion be? Take the first two digits, then add a colon and after the colon all the remaining digits (fill with zeros)?

For the logic above, do something like this:

SELECT
      nbr
      ,CASE WHEN nbr < 0 THEN '-' ELSE '' END || SUBSTR(TO_CHAR(ABS(nbr)), 1, 2) || ':' || NVL(SUBSTR(TO_CHAR(ABS(nbr)), 3, 1), 0) || NVL(SUBSTR(TO_CHAR(ABS(nbr)), 4, 1), 0) AS nbr2
FROM
(SELECT 50 AS nbr FROM dual

UNION ALL

SELECT -6000 AS nbr FROM dual

UNION ALL

SELECT -44 AS nbr FROM dual

UNION ALL

SELECT -56 AS nbr FROM dual
) asd
0
 
LVL 10

Expert Comment

by:Bawer
ID: 37795593
select to_char(column,'999,999,999,990.00') from table
0
 

Author Comment

by:neoarwin
ID: 37795667
@ bawer this won't work out.
as it will give -6000:00 , 5000:00
I need -60:00 for 6000 and 50:00 for 5000

@tosse I have many values in that table, i gave 4 values as an example..
how to change your query in that case?
0
 

Author Comment

by:neoarwin
ID: 37795679
@ tosse I found the way from your query, thanks.
0
 

Author Closing Comment

by:neoarwin
ID: 37795683
Thank you :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
Suggested Courses

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question