0

I have table that has columns with email addresses delimited by ;:

TO                                              CC                                  BCC
--------------------------------------------------------------------------------------------------------------------
[email protected];[email protected];[email protected]   [email protected];[email protected]   [email protected];[email protected]

User gives an email address as the search criteria and I have to lookup against each of these columns to find the rows where any of the colums have the target email address.

Can anyone please help me out here?

I tried using reg_exp but dont have much experience there.

Noel
  • 10,152
  • 30
  • 45
  • 67

2 Answers2

2

Simple way:

SELECT * FROM emailtable
WHERE INSTR(';' || to || ';' || cc || ';' || bcc || ';'
           ,';' || :search_parameter || ';') > 0;
Jeffrey Kemp
  • 59,135
  • 14
  • 106
  • 158
  • Hi Jeffrey, Thanks for the input,I am able to get the output .But there is slight complexity here.User has an option to select the input as begins with/contains/ends with.user might not have the complete email address.can we use % character and can we modify the query. – user2865588 Oct 10 '13 at 06:30
  • In that case you'll need to parse the columns out - see http://stackoverflow.com/questions/4004377/splitting-comma-separated-string-in-a-pl-sql-stored-proc – Jeffrey Kemp Oct 10 '13 at 10:27
0

From your requirement and from what I get from your comment on Jeffery Kemp's answer, I suggest you try the following:

SELECT *
  FROM emailtable
 WHERE lower(REPLACE ("TO" || ';' || cc || ';' || bcc, ' ', ''))
       LIKE '%' || lower(REPLACE (:search_parameter, ' ', '')) || '%'

The lower function helps us with a case insensitive search. REPLACE eliminates the spaces.

I hope this should give you a clue. This is the simplest way in which a part of email ID can be searched through the to, cc and bcc columns. Please modify the WHERE condition as per you requirements.

Rachcha
  • 8,486
  • 8
  • 48
  • 70