SSC-PRF-0004

This statement has usages of cursor for loop

Severity

None

Description

This warning is used to indicate that the statement has usages of cursor for loop. A cursor for loop is a control structure that allows to iterate over the result set one row at a time.

This scenario could be considered a complex pattern when the code inside the loop is overly complex. E.g. if the SELECT statement inside the cursor for loop returns a large result set, or if the code inside the loop involves complex operations or nested loops, the cursor for loop could become slow and inefficient. This warning is meant to be a helper to spot some problems that a static-code analyzer such as SnowConvert cannot.

Code Example

Teradata

IN -> Teradata_01.sql
REPLACE PROCEDURE teradata_cursor_for_loop()    
BEGIN
    FOR fUsgClass AS cUsgClass CURSOR FOR
        (SELECT col1
        FROM sample_table)
    DO
        SET var1 = fUsgClass.col1;
    END FOR;
END;

Oracle

IN -> Oracle_01.sql
CREATE OR REPLACE PROCEDURE oracle_cursor_for_loop AS
BEGIN
    FOR r1 IN (SELECT col1 FROM sample_table) LOOP
        NULL;
    END LOOP;
END;

Recommendations

Last updated