我正在运行以下查询:
Select ID From Players order by ID limit 3;
它给出错误
命令未正确结束。
以下查询:
SQL> Select ID From Players order by ID limit 3;
Select ID From Players order by ID limit 3
*
给出类似的错误:
第1行的错误:ORA-00933:SQL命令未正确结束
我该如何解决?
答案 0 :(得分:1)
Oracle没有或不支持限制条款,因此您会收到错误。
使用此查询:
Select ID From Players order by ID
OFFSET 0 ROWS FETCH NEXT 3 ROWS ONLY;
OR
Select ID From Players order by ID
where rownum between 1 and 3 order by ID desc;
原因:SQL语句以不合适的子句结束。
有关详细信息,请参阅this post。
答案 1 :(得分:0)
Oracle不支持limit
。 Oracle 12c支持fetch first <n> rows only
。在早期版本中,您可以使用子查询和rownum
:
select *
from (select ID
from Players
order by ID desc
) p
where rownum <= 3;