views:

53

answers:

2

Is there anyway to remove a character from a given position?

Let's say my word is: PANCAKES And I want to remove the 2nd letter (in this case, 'A'), so i want PNCAKES as my return.

Translate doesnt work for this. Replace doesnt work for this. Regex is damn complicated...

Ideas?

A: 

yes REPLACE and SUBSTR in the proper order will do the trick.

the end result should be a concatenation of the SUBSTR before the removed char to the SUBSTR after the char.

if the entire column is only one word, then you can just do an update, if the word is in another string, then you could use REPLACE as a wrapper.

Randy
An example is very appreciated.
alex
+1  A: 

Example:

SUBSTR('PANCAKES', 0, INSTR('PANCAKES', 'A', 1, 1)-1) || SUBSTR('PANCAKES', INSTR('PANCAKES', 'A', 1, 1)+1)

I don't have an Oracle instance to test with, might have to tweak the -1/+1 to get the position correct.

References:

OMG Ponies
REGEXP_REPLACE is an option for Oracle 10g+: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions130.htm#SQLRF06302
OMG Ponies
Works. Thanks! I was thinking about regex but they are kinda complicated.
alex
@alex: I highly recommend http://www.regular-expressions.info/ -it's a great resource to get more comfortable with regexes.
OMG Ponies