Phoenix favicon

Apache Phoenix

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

  1. Define a cursor for a query using the DECLARE statement.

    PreparedStatement statement = conn.prepareStatement(
        "DECLARE empCursor CURSOR FOR SELECT * FROM EMP_TABLE"
    );
    statement.execute();
  2. Open the cursor.

    statement = conn.prepareStatement("OPEN empCursor");
    statement.execute();
  3. Fetch a subset of rows to work with.

    statement = conn.prepareStatement("FETCH NEXT 10 ROWS FROM empCursor");
    ResultSet rset = statement.executeQuery();
  4. Iterate through the fetched rows and process them as required.

    while (rset.next()) {
        // ...
    }
  5. Fetch additional sets of rows as needed, and close the cursor when done.

    statement = conn.prepareStatement("CLOSE empCursor");
    statement.execute();
Edit on GitHub

On this page