15

I am executing the below query in SQL Developer.

SELECT * FROM Person where person_name='rahul' order by created_time desc limit 10;

When I execute it, SQL Developer gives me below error.

ORA-00933: SQL command not properly ended
00933. 00000 -  "SQL command not properly ended"
*Cause:    
*Action:

I used the below link for reference.

https://www.techonthenet.com/sql/select_limit.php

I already tried

SELECT * FROM Person where person_name='rahul' order by created_time desc OFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY;

ORA-00933: SQL command not properly ended
00933. 00000 -  "SQL command not properly ended"
*Cause:    
*Action:
Error at Line: 1 Column: 75

Note that OFFSET is not treated as keyword.

2
  • Any change if you remove the ; ? Commented Dec 2, 2016 at 10:01
  • No. Still the same. Commented Dec 2, 2016 at 10:09

3 Answers 3

32

Yes, that' cause Oracle don't have or support limit clause and thus you are getting ORA-00933 error. Rather, use FETCH .. OFFSET construct like

SELECT * FROM Person 
where person_name='rahul' 
order by created_time desc 
OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;
Sign up to request clarification or add additional context in comments.

Comments

5

I have resolved the issue by using the below query.

SELECT * FROM Person where person_name='rahul' and rownum between 1 and 2 order by created_time desc;

Comments

2

If you get

ORA-00933: SQL command not properly ended
00933. 00000 -  "SQL command not properly ended"
*Cause:    
*Action:

It is probably because you aren't running Oracle 12. In that case, there are some workarounds, all involving subqueries and most sloppy. I used

select * from 
    ( select column_name, ROWNUM rnum from 
        ( select * from table_name) 
    where ROWNUM <= max_row )
where rnum  >= min_row order by column_name;

1 Comment

Note that becuase the order by is not in the inner most subquery it will only order the outermost subgroup. Basically if you have 1000 records, and you fetch 100-125, it will get a random set of 25 records and sort that. I think you want the order by after the select * from table_name part.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.