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

x
?
Solved

oracle replace function

Posted on 2011-09-09
5
Medium Priority
?
461 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 78

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 74

Accepted Solution

by:
sdstuber earned 500 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 74

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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

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 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 shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
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…

885 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