高手,如何解决这个问题?

用sql语句如何找出数据库中按某字段大小排列的5条记录

select * from ( select * from cpu order by cpuname) where rownum <6
*
ERROR 位于第 1 行:
ORA-00907: 缺少右括号

---------------------------------------------------------------

怎么跟
http://expert.csdn.net/Expert/topic/1555/1555043.xml?temp=.665188
的问题一样,奇怪,可能是Oracle版本问题,你的比较低?

给子查询起个别名试试
select * from ( select * from cpu order by cpuname) a where rownum <6

---------------------------------------------------------------

Order by 不能加
---------------------------------------------------------------

确实有点怪,除去ORDERBY就可以了
---------------------------------------------------------------

oracle中在子查询中是不能用order by 语句的,不用尝试了
不过可以用游标来实现的。
---------------------------------------------------------------

SQL> select * from ( select * from tab order by tname) where rownum < 6;

TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
A TABLE
B TABLE
C TABLE
D TABLE
E TABLE

我的Oracle就支持Oracle 8.1.7
---------------------------------------------------------------

你的ORACLE版本是什么?
---------------------------------------------------------------

改用临时表吧。

create table temp as ( select rownum row_no, * from cpu order by cpuname);

select * from temp where row_no < 6;

drop table temp;

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus