Using LIKE in an Oracle IN clause

前端 未结 9 1571
情深已故
情深已故 2020-12-06 09:49

I know I can write a query that will return all rows that contain any number of values in a given column, like so:

Select * from tbl where my_col in (val1, v         


        
9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-06 10:20

    A REGEXP_LIKE will do a case-insensitive regexp search.

    select * from Users where Regexp_Like (User_Name, 'karl|anders|leif','i')
    

    This will be executed as a full table scan - just as the LIKE or solution, so the performance will be really bad if the table is not small. If it's not used often at all, it might be ok.

    If you need some kind of performance, you will need Oracle Text (or some external indexer).

    To get substring indexing with Oracle Text you will need a CONTEXT index. It's a bit involved as it's made for indexing large documents and text using a lot of smarts. If you have particular needs, such as substring searches in numbers and all words (including "the" "an" "a", spaces, etc) , you need to create custom lexers to remove some of the smart stuff...

    If you insert a lot of data, Oracle Text will not make things faster, especially if you need the index to be updated within the transactions and not periodically.

提交回复
热议问题