SELECT statement
Derby Reference Manual
69
SELECT statement
Syntax
]
[WITH {RR|RS|CS|UR}]
A SELECT statement consists of a query with an optional
, an optional
, an optional
and
optionally isolation level. The SELECT statement is so named because the typical first
word of the query construct is SELECT. (Query includes the VALUES expression and
UNION, INTERSECT, and EXCEPT expressions as well as SELECT expressions).
guarantees the ordering of the ResultSet. The
can be used to fetch only a subset of the otherwise selected
rows, possibly with an offset into the result set. The
result set's cursor updatable. The SELECT statement supports the FOR FETCH ONLY
clause. The FOR FETCH ONLY clause is synonymous with the FOR READ ONLY
clause.
You can set the isolation level in a SELECT statement using the WITH {RR|RS|CS|UR}
syntax.
For queries that do not select a specific column from the tables involved in the SELECT
statement (for example, queries that use
COUNT(*)
), the user must have at least one
column-level SELECT privilege or table-level SELECT privilege. See
for more information.
Example
-- lists the names of the expression
-- SAL+BONUS+COMM as TOTAL_PAY and
-- orders by the new name TOTAL_PAY
SELECT FIRSTNME, SALARY+BONUS+COMM AS TOTAL_PAY
FROM EMPLOYEE
ORDER BY TOTAL_PAY
-- creating an updatable cursor with a FOR UPDATE clause
-- to update the start date (PRSTDATE) and the end date (PRENDATE)
-- columns in the PROJECT table
SELECT PROJNO, PRSTDATE, PRENDATE
FROM PROJECT
FOR UPDATE OF PRSTDATE, PRENDATE
-- set the isolation level to RR for this statement only
SELECT *
FROM Flights
WHERE flight_id BETWEEN 'AA1111' AND 'AA1112'
WITH RR
A SELECT statement returns a ResultSet. A cursor is a pointer to a specific row in
ResultSet. In Java applications, all ResultSets have an underlying associated SQL
cursor, often referred to as the result set's cursor. The cursor can be updatable,
that is, you can update or delete rows as you step through the ResultSet if the
SELECT statement that generated it and its underlying query meet cursor updatability
requirements, as detailed below. The FOR UPDATE clause can be used to ensure a
compilation check that the SELECT statement meets the requiremments of a updatable
cursors, or to limit the columns that can be updated.
Note: The ORDER BY clause allows you to order the results of the SELECT. Without
the ORDER BY clause, the results are returned in random order.
Requirements for updatable cursors and updatable ResultSets