oracle replace function

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

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


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.
Question by:anumoses
  • 2
  • 2
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.
LVL 73

Accepted Solution

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

Author Comment

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.

Author Closing Comment

ID: 36510118
this solution worked. Thanks
LVL 73

Expert Comment

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


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


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

Suggested Solutions

Title # Comments Views Activity
Oracle 12c 10 100
Oracle Finace 3 48
when saving need to check if data exists in the oracle table. 33 60
Oracle Database Upgrade 13 43
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 …
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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.

744 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

10 Experts available now in Live!

Get 1:1 Help Now