Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Conversion of a number field in oracle sql

Posted on 2012-04-02
5
Medium Priority
?
390 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 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

916 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