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]]

for-range

====== FOR Statement (Integer Range) - HPL/SQL Reference ====== FOR statement executes one or more statements repeatedly for the specified range of integer values. Syntax: <code language=sql> FOR index IN [REVERSE] lower_bound..upper_bound [BY | STEP increment] LOOP statements END LOOP; </code> **Notes:** * //index// - Implicitly declared integer variable * If REVERSE is specified the index is decreased * If specified, BY (or STEP) define the iteration step, default is 1 **Examples:** <code language=sql> FOR i IN 1..10 LOOP -- i will have values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 END LOOP; </code> <code language=sql> FOR i IN REVERSE 10..1 LOOP -- i will have values: 10, 9, 8, 7, 6, 5, 4, 3, 1, 1 END LOOP; </code> <code language=sql> FOR i IN 1..10 BY 2 LOOP -- i will have values: 1, 3, 5, 7, 9 END LOOP; </code> **Compatibility:** Oracle, PostgreSQL and Netezza. **Version:** * HPL/SQL 0.1 - Introduced * HPL/SQL 0.3.31 - REVERSE behavior modified according Oracle PL/SQL [[https://issues.apache.org/jira/browse/HIVE-14382|HIVE-14382]]