Recursive DECLARE CURSOR statement
The recursive DECLARE CURSOR statement can be used to receive bills of material by means of a command.
Syntax
<recursive_declare_cursor_statement> ::= DECLARE <result_table_name> CURSOR FOR
WITH RECURSIVE <reference_name> (<alias_name>,...) AS
(<initial_select> UNION ALL <recursive_select>) <final_select>
<initial_select> ::= <query_spec>
<recursive_select> ::= <query_spec>
<final_select> ::= <select_statement>
DECLARE C CURSOR FOR
WITH RECURSIVE PX (MAJOR, MINOR, NUMBER, MAINMAJOR) AS
(SELECT W,X,Y,W FROM T WHERE W = 'aaa' UNION ALL
SELECT W,X,Y,MAINMAJOR FROM T, PX WHERE MINOR = T.W)
SELECT MAINMAJOR,MINOR,NUMBER FROM PX ORDER BY NUMBER
Explanation
If a
result table name with the specified reference name existed before the recursive DECLARE CURSOR statement was executed, the corresponding cursor is closed implicitly.