Oracle中的SQL参数限制
发布时间:2020-12-12 13:12:08 所属栏目:百科 来源:网络整理
导读:看起来Oracle SQL中有1000个参数的限制.我在生成诸如……等查询时遇到了这个问题. select * from orders where user_id IN(large list of ids over 1000) 我的解决方法是创建一个临时表,首先将用户ID插入到该表中,而不是通过JDBC发出查询,该查询在IN中有一个
看起来Oracle SQL中有1000个参数的限制.我在生成诸如……等查询时遇到了这个问题.
select * from orders where user_id IN(large list of ids over 1000) 我的解决方法是创建一个临时表,首先将用户ID插入到该表中,而不是通过JDBC发出查询,该查询在IN中有一个巨大的参数列表. 有人知道更简单的解决方法吗?由于我们正在使用Hibernate,我想知道它是否能够自动透明地执行类似的解决方法. 另一种方法是将数组传递给数据库,并在IN子句中使用TABLE()函数.这可能比临时表执行得更好.它肯定比运行多个查询更有效.但是如果你有大量的会话来做这件事,你将需要监视PGA内存使用情况.另外,我不确定将它连接到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; / (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |