Skip to content
Advertisement

How to search if a row is a substring of another row of the same column in Oracle

I have a table that contains millions of rows for names of customers as a column. I want to find if a part of a name exists within another row in the same column. E.g. If a row has value ‘Roger Federer’ and there are other rows with values, ‘Roger’ and ‘Federer’, I want the corresponding primary keys of all the three rows.

Advertisement

Answer

If you want to construct a logic related to rows, union concepts may suit well,

by the way, in string operations we’d better use collations with patterns through upper or lower functions to satisfy case-insensitivity for letters :

and no need to add already included complete name ( e.g. Roger Federer ).

Edit : An Alternative method maybe the following :

by adding a search string('&str') to make the query more dynamic as you wish. ( when prompted enter Roger Federer for str substitution variable )

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement