1.运行时报错;
2.3选不出纪录。
只有SELECT * FROM table WHERE ROWNUM<10;
才可以选出纪录。
2.3选不出纪录。
只有SELECT * FROM table WHERE ROWNUM<10;
才可以选出纪录。
解决方案 »
- oracle一个写联机重做日志的问题
- Oracle下载
- 我将dbms_lob.fileopen操作的文件修改或删除后,为什么它仍然能读取到文件?
- 请教oracle数据库移植的问题
- 执行语句“select distinct fsfybm from fee_tab”时,出现错误
- 有关两个数据表合并分组求各人得Money总和得SQL语句如何写?详情见下。
- sql查询效率
- 求教一个关于优化数据库表中数据的问题!高手请进!!急等。
- oracle 如何设置job 的环境变量
- 请大家帮忙一下错误:Caused by: java.sql.SQLException: OALL8 处于不一致状态 这个错误怎么解决呢
- 请教“Oracle的序列问题",急急急!!!
- 关于多线程的存储过程!!来者有分!
这种效率最高,但不能进行排序
如果需要排序
则
select * from (select * from (select * from tbname order by colname) where rownum<=50000) where rownum>=10000;
SELECT * FROM table WHERE ROWNUM<101
minus
SELECT * FROM table WHERE ROWNUM<91; 第三个肯定不行
ROWNUM>90 AND ROWNUM<100的确不行
在我这里还是不行啊。
SELECT * FROM table WHERE ROWNUM<101
minus
SELECT * FROM table WHERE ROWNUM<91;
正解!
select * from table1 where rownum between 2 and 5
和
SELECT * FROM table WHERE ROWNUM<101
minus
SELECT * FROM table WHERE ROWNUM<91;
都可以。我安装的是oracle上下载的oracle 9iR2
第一种没用过,不知道效率如何,第三种是一种错误的理解不可取,
select * from table1 where rownum between 2 and 5
不行。
看来是版本问题。
select * from table1 where rownum between 2 and 5
不行。
看来是版本问题。
在 8和8i下都不行
1. rownum的用法: 操作符只能用"<","=",不能用">". 因此,第三种
方式是错误的
2. Minus是返回查询区间,例如1里面的 rownum<101 minus rownum<91
返回的是rownum=90-100之间的数据
3. between 语句在9i可用,在8i(8.1.7.0)也可用.我测试过了. 4. 方法2在大数据量查询时确实效率很低,下面我贴一篇
ASKTOM.ORACLE.COM上提供的方法 获得查询结果
select * from (select a.*, rownum r from
(select * from t where x = :host_variable order by y ) a
where rownum < :HigerBound )
where r > :LowerBound 记住: 要用绑定变量来实现. 如果上面的代码执行太慢,可考虑下面的办法: . 创建一个记录用户点击信息的表 hits
create table hits( sess_id number, seqno number,
rid rowid, primary key(sess_id,seqno));
.. pass that userenv('sessionid') from page to page
as a hidden variable then to identify the result set. cnt := 0;
for y in ( select t.rowid rid from t where x = :host_variable
order by y )
loop
cnt := cnt + 1;
insert into hits values ( userenv('sessionid'), cnt, y.rid);
end loop; ... query
select * from t, hits
where hits.seqno between :lowBound and :highBound
and hits.sess_id = :theSessionId
order by hits.sess_id, hits.seqno
followup to comment one below the rowid is simply a primary key. Use the true primary key instead.
Lets say you needed to do this for EMP and DEPT, you might do: insert into hits
select SESSION_ID, rownum, empno, deptno
from ( select ename, dname
from emp, dept
where emp.deptno = dept.deptno
order by emp.ename ); Now, to display rows 100 - 110 you would: select emp.ename, dept.dname
from hits, emp, dept
where emp.empno = hits.empno
and dept.deptno = hits.deptno
and sequence_col between :min and :max
and session_id = :session_id; You can use the rowids of the underlying tables as well. 说明: TOM给出的方法也用到了between,and,可见是可行的.