Features
Cursor
Use CURSOR statements in Phoenix to process query results in controlled row batches.
To work on a subset of rows from a query, Phoenix supports a CURSOR control structure. The sequence below shows how to use a cursor.
Using a cursor
-
Define a cursor for a query using the
DECLAREstatement.PreparedStatement statement = conn.prepareStatement( "DECLARE empCursor CURSOR FOR SELECT * FROM EMP_TABLE" ); statement.execute(); -
Open the cursor.
statement = conn.prepareStatement("OPEN empCursor"); statement.execute(); -
Fetch a subset of rows to work with.
statement = conn.prepareStatement("FETCH NEXT 10 ROWS FROM empCursor"); ResultSet rset = statement.executeQuery(); -
Iterate through the fetched rows and process them as required.
while (rset.next()) { // ... } -
Fetch additional sets of rows as needed, and close the cursor when done.
statement = conn.prepareStatement("CLOSE empCursor"); statement.execute();