If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Replace character from string

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-19-04, 01:47
paginit paginit is offline
Registered User
 
Join Date: Jan 2004
Location: India
Posts: 191
Replace character from string

Hi,

How to replace specific character from a string.
I have '100001'
i want to replace 2nd chracter '0' with '1' .i.e.
Result output would be

'110001'

Can we do it by using oracle function i.e Replace and transalate

Thanks
Paginit
__________________
Pagnint
(No need to search web before posting new question)
Reply With Quote
  #2 (permalink)  
Old 01-19-04, 06:00
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: Replace character from string

You could change this specific string using REPLACE:

REPLACE('100001','10','11')

But in general, that would not work - e.g. it would not work for the string '100010', because it would change the 2nd and 6th characters both to 1.

To specificy a particular character position for change you must use SUBSTR:

SUBSTR(string,1,1) || '1' || SUBSTR(string, 3)

This takes the first character, appends a '1', and then appends the rest of the string from position 3 (omitting position 2).
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On