Varying IN Lists

LIKE Method

If separate variables are not an option and dynamic SQL is a "no no" then the following approach is the next simplest technique. It will not perform well in most cases however because its design prevents the use of any indexes that may exist on KEY.

variable d varchar2

execute :d := ','

variable p varchar2(100)

execute :p := '1,3,5'

select *
from   t
where  :d || :p || :d like '%' || :d || to_char(key) || :d  || '%' ;
 
       KEY C
---------- ----------
         1 v1
         3 v3
         5 v5
 

For applications where the base table contains a small number of rows or an indexed scan would not be possible regardless of the technique employed, this method may suffice.




Linking to SQL Snippets ™

To link to this page in Oracle Technology Network Forums or OraFAQ Forums cut and paste this code.

  • [url=http://www.sqlsnippets.com/en/topic-12441.html]SQL Snippets: Varying IN Lists - LIKE Method[/url]

To link to this page in HTML documents or Blogger comments cut and paste this code.

  • <a href="http://www.sqlsnippets.com/en/topic-12441.html">SQL Snippets: Varying IN Lists - LIKE Method</a>

To link to this page in other web sites use the following values.

  • Link Text : SQL Snippets: Varying IN Lists - LIKE Method
  • URL (href): http://www.sqlsnippets.com/en/topic-12441.html