Solved

oracle replace function

Posted on 2011-09-09
5
429 Views
Last Modified: 2012-05-12
I have a query

  select  to_number(replace(10.00,'.'),'9999D00') as total_hours from dual

TOTAL_HOURS
10

--------------
I need to format this to 1000 tthat is what is being stored in the database. I tired 9999, 9900, 9999D00 but am not aboe to format. Help is appreciated.
0
Comment
Question by:anumoses
  • 2
  • 2
5 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36510046
Try this:
select  to_number(replace('10.00','.'),'0000D00') as total_hours from dual;


I added single quotes to the 10.0 to remove implicit conversion issues.
0
 
LVL 73

Accepted Solution

by:
sdstuber earned 125 total points
ID: 36510057
replace only works on strings   10.00 is a number

so you'll get an implicit conversion

what are you really trying to do?


why not just do...  

( 10.00 * 100 )

and not try to do all the string manipulations
0
 
LVL 6

Author Comment

by:anumoses
ID: 36510090
total_hours is number with a format 9999.99. On saving in the database has to be saved as 1000, also a number.
0
 
LVL 6

Author Closing Comment

by:anumoses
ID: 36510118
this solution worked. Thanks
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 36510189
by the way,  the problem was using replace "before" converting to a string with a format


to_number(replace(to_char(10.00,'fm99999D00'),'.'))

I still don't recommend this though,  simply multiplying by 100 is not only easier but more efficient

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert Oracle data into XML document 2 67
Oracle dataguard 5 32
Oracle encryption 12 34
Input a SQl, output tables amd columns used in the SQL 19 35
Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

831 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