Solved

Conversion of a number field in oracle sql

Posted on 2012-04-02
5
354 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now