Fetch-Next Statement

The fetch-next statement fetches sequentially forward beginning at the current position (cursor position) in the result set and sets the cursor position to the last row fetched. After the execution of a query (SQL SELECT command), the cursor position is set to the first row of the result set. Ident is the name of the cursor used with the respective SQL SELECT command. Expr is an integer expression that specifies the number of rows to be fetched sequentially. If no more rows can be fetched, the eos condition (end of selection) is set for the cursor used in the fetch statement.

Note: To fetch the first row of a result set, no fetch-next statement must be called. Silk Performer automatically fetches the first row when a SQL SELECT command is called.

Syntax

Stat = "fetch" Ident "next" Expr.

Example

var
  v_artname : string; 
  v_artno, v_price : number;

dcltrans
  transaction TMain
  begin
    c1: SelArticle();
    fetch c1 next 5;
  end TMain;

dclsql
  SelArticle:
  SELECT articlenumber, price, name
  INTO :v_artno, :v_price, :v_artname
  FROM article
  WHERE price > 100
  ORDER BY price DESC;

After execution of the SQL command SelArticle, a result set is formed containing all articles where the price is greater than 100. The row position is set to the first row in the result set. At this time the values of the first row are bound to the variables v_artno, v_price and v_artname. The fetch c1 next 5 statement fetches 5 rows sequentially forward starting from the current row position. The row position after the fetch statement is set to the sixth row in the result set. At this time the values of the sixth row are bound to the variables v_artno, v_price and v_artname.