Using REPLACE function in Oracle

Using REPLACE more than once for same string?

Page 1 of 1

0 Replies - 3262 Views - Last Post: 13 March 2009 - 09:42 AM

#1 kelvin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-August 08

Using REPLACE function in Oracle

Post icon  Posted 13 March 2009 - 09:42 AM

In a recent homework assignment which I assume is designed to use the REPLACE function for Oracle I get the following question:

"Add the columns that follow to your [previous] result set...The vendor_phone column with the parts of the number separated by dots as in 555.555.5555".

The sample data is like: (555)555-5555 in a column called vendor_phone

My code takes care of ONE item, but not all 3 instances of '(', ')' and '-'.

Here is my code so far:

SELECT vendor_phone, REPLACE(vendor_phone,'-','.')
FROM vendors

I have tried variations to use REPLACE function multiple times in the code, such as:
SELECT vendor_phone, REPLACE(vendor_phone,'-','.'), REPLACE(vendor_phone,')','.'
FROM vendors

BUT of course that does not work.... so my question (a beginners question for sure--which I am in Oracle and SQL):

How do I use REPLACE function for multiple instances that need to change in same item such as the "vendor_phone"? Or am I on the wrong track using a REPLACE function at all?

Is This A Good Question/Topic? 0
  • +

Page 1 of 1