Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use multiple values with like in sql

 select * from user_table where name in ('123%','test%','dummy%')

How to ensure that this where clause is not an exact match, but a like condition?

like image 360
Madhu Velayudhan Avatar asked Oct 21 '25 13:10

Madhu Velayudhan


1 Answers

In Oracle you can use regexp_like as follows:

select *
from   user_table
where  regexp_like (name, '^(123|test|dummy)')

The caret (^) requires that the match is at the start of name, and the pipe | acts as an OR.

Be careful though, because with regular expressions you almost certainly lose the benefit of an index that might exist on name.

like image 101
trincot Avatar answered Oct 24 '25 05:10

trincot