Home » SQL & PL/SQL » SQL & PL/SQL » REGEXP_REPLACE for different name variations (Oracle 11g)
REGEXP_REPLACE for different name variations [message #639090] Wed, 01 July 2015 07:35 Go to next message
madsen
Messages: 6
Registered: July 2014
Junior Member
I am trying to use REGEXP_REPLACE to clean up the names of entities of any .INC,CO., LTD. etc.

I am using:

SELECT X, trim(REGEXP_REPLACE(upper(regexp_replace (X,'[^[:alnum:]'' '']', NULL)), '\INCORPORATED$|\INC$|\ LLC$|\ CORPORATION$|\LTD$|\INTL$|\SA CI$|\CO LTD$|\SA$|\LIMITED$|\SA DE CV$|\LTD$|\$|\LLC$|\BRANCH$|\ CO$|\CORP$|\ LLC CO B$|\PTE$'))
 FROM my_data;


Is there a better way?
Re: REGEXP_REPLACE for different name variations [message #639091 is a reply to message #639090] Wed, 01 July 2015 07:38 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Is there a better way?

which metric measures better?

Realize that we don't have your table or data, therefore can't run your posted code.
How do we know what are expected/desired results?
Re: REGEXP_REPLACE for different name variations [message #639092 is a reply to message #639090] Wed, 01 July 2015 07:42 Go to previous messageGo to next message
Michel Cadot
Messages: 68643
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
Is there a better way?


Yes.

Re: REGEXP_REPLACE for different name variations [message #639093 is a reply to message #639091] Wed, 01 July 2015 08:17 Go to previous messageGo to next message
madsen
Messages: 6
Registered: July 2014
Junior Member
I understand you don't have my data. Again: I need a code that would remove .INC , .CO, .LTD, , two letter words, abbreviations along with commas, slashes and any special characters from the names of different entities.

Everytime I ask a question people our trying to come up with a sarcastic answer like Michel Cadot here which is everything but helpful.

And my definition of "better way" would be more efficient.
I appologize if I wasn't 100% precise in my initial quesiton, please understand that English is not my first language.

Thank you
Re: REGEXP_REPLACE for different name variations [message #639095 is a reply to message #639090] Wed, 01 July 2015 08:23 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
The only two methods that come to mine are regexp_replace, which you are already using, and nested replace statements. Usually, with something simple, replace is faster, but with more complex things regexp_replace is faster. You might try testing and running both and comparing.

I am curious why you are removing these official portions of the names. If it is to enable simpler searches, then there may be a better way to search, such as using Oracle Text, without removing the official parts of the names.
Re: REGEXP_REPLACE for different name variations [message #639096 is a reply to message #639093] Wed, 01 July 2015 08:57 Go to previous message
Michel Cadot
Messages: 68643
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Your query simply does not work:

SQL> SELECT X, trim(REGEXP_REPLACE(upper(regexp_replace (X,'[^[:alnum:]'' '']', NULL)), '\INCORPORATED$|\INC$|\ LLC$|\ CORPORATION$|\LTD$|\INTL$|\SA CI$|\CO LTD$|\SA$|\LIMITED$|\SA DE CV$|\LTD$|\$|\LLC$|\BRANCH$|\ CO$|\CORP$|\ LLC CO B
$|\PTE$'))
2 FROM my_data;
FROM my_data
*
ERROR at line 2:
ORA-00942: table or view does not exist

Quote:
Everytime I ask a question people our trying to come up with a sarcastic answer like Michel Cadot


Maybe because each time you incorrectly post your question, maybe it would help if you rea and follow OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.

Note: With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.

[Updated on: Wed, 01 July 2015 08:59]

Report message to a moderator

Previous Topic: REGEXP_REPLACE DISTINCT Mixed results
Next Topic: construct full date based on value yyyymm
Goto Forum:
  


Current Time: Tue Apr 23 09:25:44 CDT 2024