select * from orders where user_id IN(large list of ids over 1000)
我的解决方法是创建一个临时表,首先将用户ID插入到该表中,而不是通过JDBC发出查询,该查询在IN中有一个巨大的参数列表.
有人知道更简单的解决方法吗?由于我们正在使用Hibernate,我想知道它是否能够自动透明地执行类似的解决方法.
注意:TABLE()函数在SQL引擎中运行,因此它们需要我们声明SQL类型.
create or replace type tags_nt as table of varchar2(10); /
以下示例使用几千个随机标记填充数组.然后它使用查询的IN子句中的数组.
declare search_tags tags_nt; n pls_integer; begin select name bulk collect into search_tags from ( select name from temp_tags order by dbms_random.value ) where rownum <= 2000; select count(*) into n from big_table where name in ( select * from table (search_tags) ); dbms_output.put_line('tags match '||n||' rows!'); end; /