Solved

Conversion of a number field in oracle sql

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle 12c Default Isolation Level 17 64
subtr returning incorrect value 8 99
error in oracle form 11 53
Shared Service Environment 2 54
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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 recover a database from a user managed backup

751 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