fetch

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

fetch [2015/09/23 20:27] (current)
Line 1: Line 1:
 +====== FETCH Statement - PL/HQL Reference ======
  
 +FETCH statement retrieve the next row from a cursor and assigns column values to local variable.
 +
 +**Syntax**:
 +
 +<code language=sql>​
 +FETCH [FROM] cursor_name INTO var1 [, var2, ...];
 +</​code>​
 +
 +**Parameters:​**
 +
 +| **Parameter** | **Type** | **Value** | **Description** |
 +| cursor_name | | Identifier | The name of the previously opened cursor |
 +| varN | | Variable | A local variable |
 +
 +**Examples:​**
 +
 +<code language=sql>​
 +DECLARE tabname VARCHAR DEFAULT '​db.orders';​
 +DECLARE id INT;
 +DECLARE cur CURSOR FOR '​SELECT id FROM ' || tabname;
 +OPEN cur;
 +FETCH cur INTO id;
 +WHILE SQLCODE=0 THEN
 +  PRINT id;
 +  FETCH cur INTO id;
 +END WHILE;
 +CLOSE cur;
 +</​code>​
 +
 +**Compatibility:​** Oracle, IBM DB2, Teradata, SQL Server, MySQL, PostgreSQL and Netezza.
 +
 +**See also:**
 +  * [[declare-cursor|DECLARE CURSOR]]
 +  * [[open|OPEN]]
 +  * [[close|CLOSE]]
 +  * [[sqlcode|SQLCODE]]