PreparedStatement IN clause alternatives?

前端 未结 30 4480
情歌与酒
情歌与酒 2020-11-21 05:19

What are the best workarounds for using a SQL IN clause with instances of java.sql.PreparedStatement, which is not supported for multiple values du

30条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-21 05:41

    For some situations regexp might help. Here is an example I've checked on Oracle, and it works.

    select * from my_table where REGEXP_LIKE (search_column, 'value1|value2')
    

    But there is a number of drawbacks with it:

    1. Any column it applied should be converted to varchar/char, at least implicitly.
    2. Need to be careful with special characters.
    3. It can slow down performance - in my case IN version uses index and range scan, and REGEXP version do full scan.

提交回复
热议问题