0

Hi,

I have a select statement and I need to find a way to apply a filter to it:

select * from my_table where my_table.field_1 like :filter_item

The real problem is that filter_item can be a string, a string that includes '%' or a comma-separated string that can include wildcard like this:

abc, abgf%fri, e%ij%fd, abcd

The best way would be to solve this without creating any special package/function, etc. But if there is no other way then any solution is welcome.

Thanks,
Ender

3
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by end3r
0

The problem is that the :filter_item = 'abc, abgf%fri, e%ij%fd, abcd'.
So the select will look like:

SELECT * FROM my_table WHERE my_table.field_1 LIKE 'abc, abgf%fri, e%ij%fd, abcd'

I need to split this and have the following functionality:

SELECT * FROM my_table 
WHERE my_table.field_1 LIKE 'abc'
OR my_table.field_1 LIKE 'abgf%fri'
OR my_table.field_1 LIKE 'e%ij%fd'
OR my_table.field_1 LIKE 'abcd'

Do you have a solution for this ?

0

I think there is a solution using the REGEXP_LIKE function. The only problem is that I am not sure what regular expression should be used.

0

Generally filterItem is being passed in from code (PHP, JSP, C#, etc.).

This would be the place to break that out into an array, separating on commas, then either reparse into separate "OR"s or pass in as separate parameters.

I'm guessing you're doing some sort of search on keywords?

0

Hy,

I finally found the solution, so in case anyone encounters the same problem, here is the condition for searching an IP_ADDRESS column by a comma-separated list of IPs:

-- YOUR CODE....
AND REGEXP_LIKE(IP_ADDRESS, REPLACE(REPLACE(REPLACE(REPLACE(NVL(:IP_ADDRESS_LIST, '%.%.%.%'), ', ', '$|'), ',', '$|'), '%', '[0-9]{1,3}'), '.', '\.') || '$' )

Best Regards,
Ender

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.