我现在要select 查询获取一个结果集
例如:select a.row1 from table tb a
where a.id=?我现在有很多id ,id =1,2,3,4,5,6,7,......n1,java 里面用for循环
for(int i=1; i<n;i++)
{
调用查询
select a.row1 from table tb a where a.id=i;
}2,直接调用查询
select a.row1 from table tb a where a.id in (1,2,3,4,....n)那个速度快呢?
例如:select a.row1 from table tb a
where a.id=?我现在有很多id ,id =1,2,3,4,5,6,7,......n1,java 里面用for循环
for(int i=1; i<n;i++)
{
调用查询
select a.row1 from table tb a where a.id=i;
}2,直接调用查询
select a.row1 from table tb a where a.id in (1,2,3,4,....n)那个速度快呢?
解决方案 »
- 关于create database link的问题。急,快点进来,谢谢
- oracle求统计SQL
- oracle开始-程序-的enterprises manager console图表不见了
- oracle做DBLINK查询后,为什么要roll back呢?
- 求sql语句将数据库表某些字段的内容翻10倍
- 查询24小时各时间段的记录
- input 中 column sal heading 'monthly salary'的作用是什么
- ORACLE是不是下载不了呀???
- 怎样给表加锁
- 为何在red hat 7.2上装不上 oracle8.1.7
- 很急
- [请教]Failed to commit the transaction: … caused by: ORA-00018: maximum number of
select a.row1 from table tb a where a.id in (1,2,3,4,....n)
如果in中的列大于1000后,数据库会报错!可以考虑用第2种方式,在java中把in后的控制在1000以内,然后批量提交。
你要明白oracle的工作方式,
每次提交sql都要有开销,oracle会分配内存,游标,解析语句,验证语法,安全.
然后生成查询计划,
最后再开始真正的查询.
(
ID int
);--然后运行declare i int;
begin
i:=1;
while i<=10000
loop
insert into t values(i);
i:=i+1;
end loop;
end;--10000个ID值不知道够不够--然后关联select a.row1
from tb as a, (select id from t where id <= n) as b
where a.row1 = b.id--建议row1有索引.....
2、如果ID太多会出现错误的~SQL语句的长度有限制的!
可以尝试将ID放入数据库中
然后在数据库做连接查询。我个人感觉这种方式不错!
--如果没有的话,还不如直接:
where a.id>= min_id and a.id<=max_id;
-- 其中:min_id 是你传过来的的所有ID中最少的ID,max_id是你传过来的所有ID中最大的ID!