-1

I'm try to select only 10 row from a table by using limit but it gives me an error,

My query is

SELECT * 
FROM table_name
ORDER BY CUSTOMER
LIMIT 10

It gives an error :

ORA-00933: SQL command not properly ended

Can anyone guide me.

User
  • 69
  • 1
  • 12
  • It is very hard for anyone to help with only saying "its giving me an error". Elaborate on the specific issue or it isn't likely anyone can help you. – Turnerj Feb 14 '15 at 07:38
  • Select * from table_name order by CUSTOMER limit 10; – User Feb 14 '15 at 07:48
  • ORA-00933: SQL command not properly ended is the error i m getting – User Feb 14 '15 at 07:48

1 Answers1

6

You can use ROWNUM :

SELECT *
FROM ( SELECT * 
       FROM table_name
       ORDER BY CUSTOMER) t 
WHERE ROWNUM <=10

For each row returned by a query, the ROWNUM pseudocolumn returns a number indicating the order in which Oracle selects the row from a table or set of joined rows. The first row selected has a ROWNUM of 1, the second has 2, and so on.

Or, since Oracle 12c r1, you can use FETCH :

SELECT * 
FROM table_name
ORDER BY CUSTOMER
FETCH FIRST 10 ROWS ONLY

FETCH
Use this clause to specify the number of rows or percentage of rows to return. If you do not specify this clause, then all rows are returned, beginning at row offset + 1.
FIRST | NEXT
These keywords can be used interchangeably and are provided for semantic clarity.

potashin
  • 42,140
  • 11
  • 76
  • 100
  • @SadiaGhazal : You are welcome. I don't really know how to elaborate better, than providing an information from the docs, since the only keyword is involved and solution is not represented as a workaround. – potashin Feb 14 '15 at 08:08
  • SELECT * FROM table_name ORDER BY CUSTOMER FETCH FIRST 10 ROWS ONLY is giving error saying sql command not ended properly – User Feb 14 '15 at 08:08
  • @Sadia Ghazal : What it your Oracle RDBMS version? As I said, this functionality is for *12c r1* and higher. – potashin Feb 14 '15 at 08:09