如何select只有table中的10条记录在jsp中?
How to select only 10 records from the table in jsp?
我尝试使用 limit
从 table 中仅 select 10 行,但它给了我一个错误,
My query is
SELECT *
FROM table_name
ORDER BY CUSTOMER
LIMIT 10
报错:
ORA-00933: SQL command not properly ended
谁能指导一下。
您可以使用 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.
或者,自 Oracle 12c r1,您可以使用 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.
我尝试使用 limit
从 table 中仅 select 10 行,但它给了我一个错误,
My query is
SELECT *
FROM table_name
ORDER BY CUSTOMER
LIMIT 10
报错:
ORA-00933: SQL command not properly ended
谁能指导一下。
您可以使用 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.
或者,自 Oracle 12c r1,您可以使用 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.