改SQL,参数太多了,只有想其他办法
比如:select *
from table
where id in (1, 2, .. ., 1000)
union all
select *
from table
where id in (1001, .... ., 1999)
比如:select *
from table
where id in (1, 2, .. ., 1000)
union all
select *
from table
where id in (1001, .... ., 1999)
比如:select *
from table
where id in (1, 2, .. ., 1000)
union all
select *
from table
where id in (1001, .... ., 1999)
这种方式效率会比or的方式高吗?
另外,由于这种方式相当于把整个sql重复n次,如果原来的sql就很长很复杂,这种方式得到的sql岂不是还要成倍的增加?
from table
where id in (
select 1 from dual
union all
select 2 from dual
……)
这么写没个数限制
不过还是建议建临时表,把in里面的数据插入到临时表中,然后用临时表写条件查询
比如:
select *
from table
where id in (1, 2, .. ., 1000)
union all
select *
from table
where id in (1001, .... ., 1999)
这种方式效率会比or的方式高吗?
另外,由于这种方式相当于把整个sql重复n次,如果原来的sql就很长很复杂,这种方式得到的sql岂不是还要成倍的增加?
看索引怎么建的了,使用or的话很容易不走索引而使用全表扫描
请问临时表要怎么建呢?我是通过java 操作数据库的
select * from t where id in (select id from temp)
他的问题和你那个可不一样,他这个是业务数据
如果还嫌慢的话可以插入是加上append参数,这样不用写日志,直接写入数据库
insert /*+append*/ into
如果还嫌慢的话可以插入是加上append参数,这样不用写日志,直接写入数据库
insert /*+append*/ into
感谢版主解答,现在基本解决问题了