User Tools

Site Tools


Sidebar

**HPL/SQL is included to Apache Hive since version 2.0** * [[home|Home]]\\ * [[why|Why HPL/SQL]]\\ * [[features|Key Features]]\\ * [[start|Get Started]]\\ * [[doc|HPL/SQL Reference]]\\ * [[download|Download]]\\ * [[new|What's New]]\\ * [[about|About]]

open

====== OPEN Statement - PL/HQL Reference ====== OPEN statement opens a cursor. **Syntax**: <code language=sql> OPEN cursor_name [FOR expression | select_statement]; </code> **Description:** | cursor_name | The name of the previously declared cursor if FOR clause is not specified | | FOR expression | Variable or expression that contains a dynamic SQL | | FOR select_statement | SELECT statement | **Examples:** Open the previously declared cursor: <code language=sql> DECLARE tabname VARCHAR(20) 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> Open a cursor using a dynamic SQL: <code language=sql> DECLARE tabname VARCHAR(20) DEFAULT 'db.orders'; DECLARE id INT; OPEN cur FOR 'SELECT id FROM ' || tabname; 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, PostgreSQL, MySQL and Netezza. **See also:** * [[declare-cursor|DECLARE CURSOR]] * [[fetch|FETCH]] * [[close|CLOSE]] * [[sqlcode|SQLCODE]]