This shows you the differences between two versions of the page.
— |
for-cursor [2015/09/23 20:27] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== FOR Statement (Cursor Loop) - PL/HQL Reference ====== | ||
+ | FOR statement opens a cursor, executes one or more statements repeatedly for each row and closes the cursor. | ||
+ | |||
+ | Syntax: | ||
+ | |||
+ | <code language=sql> | ||
+ | FOR cur_name IN [(] select_stmt [)] LOOP | ||
+ | statements | ||
+ | END LOOP; | ||
+ | </code> | ||
+ | |||
+ | **Notes:** | ||
+ | |||
+ | * You can refer to the cursor columns using //cur_name.col_name// syntax | ||
+ | |||
+ | **Example:** | ||
+ | |||
+ | <code language=sql> | ||
+ | FOR item IN ( | ||
+ | SELECT dname, loc as location | ||
+ | FROM dept | ||
+ | WHERE dname LIKE '%A%' | ||
+ | AND deptno > 10 | ||
+ | ORDER BY location) | ||
+ | LOOP | ||
+ | DBMS_OUTPUT.PUT_LINE('Name = ' || item.dname || ', Location = ' || item.location); | ||
+ | END LOOP; | ||
+ | </code> | ||
+ | |||
+ | **Compatibility:** Oracle, PostgreSQL and Netezza | ||
+ | |||
+ | **Version:** PL/HQL 0.03 |