Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Oracle replace string question

Posted on 2014-01-21
6
Medium Priority
?
605 Views
Last Modified: 2014-01-23
Could you please suggest how can I replace a string like the followings:

Something..bIgdOg..sMALlcaT..SomethingMore
Something..bIgdoG..sMaLlcaT..SomethingMore
Something..bIGDog..smaLLcat..SomethingMore


with the following:
Something..BigDog..SmallCat..SomethingMore

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.
0
Comment
Question by:toooki
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 23

Expert Comment

by:Steve Wales
ID: 39798976
There is a builtin function called INITCAP that will capitalize each word:

SQL> select initcap('SmallCAT..BigDog') from dual;

INITCAP('SMALLCA
----------------
Smallcat..Bigdog

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
0
 

Author Comment

by:toooki
ID: 39798983
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.
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 total points
ID: 39799078
select
     regexp_replace(
          regexp_replace(yourcolumn,'[bB][iI][gG][dD][oO][gG]','BigDog'),
          '[sS][mM][aA][lL]{2}[cC][aA][tT]','SmallCat')
from yourtable

Open in new window



or, use case insensitive search...


select
      regexp_replace(
                   regexp_replace(yourcolumn,'bigdog','BigDog',1,0,'i'),
                   'smallcat','SmallCat',1,0,'i')
from yourtable

Open in new window

0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 32

Expert Comment

by:awking00
ID: 39800681
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?
0
 

Author Comment

by:toooki
ID: 39801883
Thank you!
The query
select
     regexp_replace(
          regexp_replace(yourcolumn,'[bB][iI][gG][dD][oO][gG]','BigDog'),
          '[sS][mM][aA][lL]{2}[cC][aA][tT]','SmallCat')
from yourtable
perfectly worked for me. Many thanks!
0
 
LVL 32

Expert Comment

by:awking00
ID: 39803014
So the part of the string that needs to be replaced is always the same (i.e. BigDog and SmallCat)?
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

636 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