I need to implement a search query, where we have multiple filters(values) for a single column in database(oracle). But these multiple filters(values) are LIKE
quer
As was already commented, it is better and simpler to just concatenate several conditions:
where departmentName like '%Medi%'
or departmentName like '%Ciga%'
or departmentName like '%Tabacc%';
Another way is to insert those values '%Medi%', '%Ciga%' and '%Tabacc%' into a conditionTable, and then run this query:
select department.*
from department
cross join conditionTable
where department.departmentName like conditionTable.value;
I am assuming here that your table is department
and that the conditionTable has a column value
. If you implement this solution, you should care about concurrency, and filter conditionTable by something like
select department.*
from department
inner join conditionTable on conditionTable.session = yourSessionId
where department.departmentName like conditionTable.value;
Finally, a third solution that might be handy, if you dont want to use a conditionTable, is to generate a string select <cond1> as value from dual union select <cond2> from dual...
and placed into a dynamic query as
select department.*
from department
cross join
(select '%Medi%' as value from dual
union
select '%Ciga%' from dual
union
select '%Tabacc%' from dual) conditionTable
where department.departmentName like conditionTable.value;