cancel
Showing results for 
Search instead for 
Did you mean: 

recognize and exclude sql comments in SELECT LIKE statement

Baron
Participant
1,101

Is it possible to look for a specific text and distinguish whether the matched text exists in a comment?

Something like this:

select 'really found' where 'select * from ABC;' like '%ABC%';
select 'found only in comments' where 'select * from mytable;--other table than ABC' like '%ABC%';
this works, but I want to prevent this working:
select 'really found' where 'select * from mytable;--other table than ABC' like '%ABC%';
select 'found only in comments' where 'select * from ABC;' like '%ABC%';

Accepted Solutions (0)

Answers (1)

Answers (1)

MCMartin
Participant

have you checked the REGEXP search condition to solve the match inside a comment? Eventually using --.*?ABC.*?

VolkerBarth
Contributor
0 Kudos

I guess it should also be considered that a new line ends a "--comment" or "// comment" so text in the next line up to the next comment indicator must be recognized as non-comment - which should work with according REGEXP expressions when adding '\\n', too.