toooki
asked on
Oracle replace string question
Could you please suggest how can I replace a string like the followings:
Something..bIgdOg..sMALlca T..Somethi ngMore
Something..bIgdoG..sMaLlca T..Somethi ngMore
Something..bIGDog..smaLLca t..Somethi ngMore
with the following:
Something..BigDog..SmallCa t..Somethi ngMore
Using a oracle select statement with regex_replace or replace queries that is small (readable)? The input string has random upper and lower cases for the words BigDog and SmallCat.
Thank you.
Something..bIgdOg..sMALlca
Something..bIgdoG..sMaLlca
Something..bIGDog..smaLLca
with the following:
Something..BigDog..SmallCa
Using a oracle select statement with regex_replace or replace queries that is small (readable)? The input string has random upper and lower cases for the words BigDog and SmallCat.
Thank you.
ASKER
Thank you. But I cannot change the rest of the string (Something and SomethingMore and these contents are unknown. So Initcap will not work well.
I could repeatedly use the replace statement for all combination of the SmallCAT and BigDog strings with cap/small letter mix but that will look the query unreadable.
I could repeatedly use the replace statement for all combination of the SmallCAT and BigDog strings with cap/small letter mix but that will look the query unreadable.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Without a means of identifying that a string is made up of separate words (i.e. separated by underscores or slashes or such), I don't think this can be accomplished. Except for the case, are the strings always the same or could something like rEaltInYMousE also exist?
ASKER
Thank you!
The query
select
regexp_replace(
regexp_replace(yourcolumn, '[bB][iI][ gG][dD][oO ][gG]','Bi gDog'),
'[sS][mM][aA][lL]{2}[cC][a A][tT]','S mallCat')
from yourtable
perfectly worked for me. Many thanks!
The query
select
regexp_replace(
regexp_replace(yourcolumn,
'[sS][mM][aA][lL]{2}[cC][a
from yourtable
perfectly worked for me. Many thanks!
So the part of the string that needs to be replaced is always the same (i.e. BigDog and SmallCat)?
Open in new window
That's great and all, but what rule would you use to set the capital in the middle of the word since that's kinda arbitrary given the examples above