With each iteration of the FORLOOP statement, its statements run, its index is either incremented or decremented, and control returns to the top of the loop. (Oracle PL/SQL Language Reference FOR LOOP Statement).
Snowflake Scripting supports FOR LOOP that loops a specified number of times. The upper and lower bounds must be INTEGER. Check more information in the Snowflake Scripting documentation.
Oracle FOR LOOP behavior can also be modified by using the statements:
CREATEORREPLACEPROCEDURE P1ASBEGINFOR i IN1..10LOOPNULL;ENDLOOP;FOR i IN VAR1..VAR2LOOPNULL;ENDLOOP; FOR i IN REVERSE 1+2..10+5LOOPNULL;ENDLOOP; END;
OUT -> Oracle_01.sql
CREATEORREPLACEPROCEDURE P1 ()RETURNSVARCHARLANGUAGESQLCOMMENT = '{"origin":"sf_sc","name":"snowconvert","version":{"major":1, "minor":0},{"attributes":{"component":"oracle"}}'
EXECUTEASCALLERAS$$BEGINFOR i IN1TO10LOOPNULL;ENDLOOP;FOR i IN VAR1 TO VAR2 LOOPNULL;ENDLOOP;FOR i IN REVERSE 1+2TO10+5LOOPNULL;ENDLOOP;END;$$;
2. FOR LOOP with additional clauses
IN -> Oracle_02.sql
CREATEORREPLACEPROCEDURE P2ASBEGINFOR i IN1..10WHILE i <=5LOOPNULL;ENDLOOP;FOR i IN5..15BY5LOOPNULL;ENDLOOP;END;
OUT -> Oracle_02.sql
CREATEORREPLACEPROCEDURE P2 ()RETURNSVARCHARLANGUAGESQLCOMMENT = '{"origin":"sf_sc","name":"snowconvert","version":{"major":1, "minor":0},{"attributes":{"component":"oracle"}}'
EXECUTEASCALLERAS$$BEGIN !!!RESOLVE EWI!!! /*** SSC-EWI-OR0101 - FOR LOOP WITH "WHILE" CLAUSE IS CURRENTLY NOT SUPPORTED BY SNOWFLAKE SCRIPTING ***/!!!
FOR i IN1TO10LOOPNULL;ENDLOOP; !!!RESOLVE EWI!!! /*** SSC-EWI-OR0101 - FOR LOOP WITH "BY" CLAUSE IS CURRENTLY NOT SUPPORTED BY SNOWFLAKE SCRIPTING ***/!!!
FOR i IN5TO15LOOPNULL;ENDLOOP;END;$$;
3. FOR LOOP with multiple conditions
IN -> Oracle_03.sql
CREATEORREPLACEPROCEDURE P3ASBEGINFOR i IN REVERSE 1..3, REVERSE i+5..i+7LOOPNULL;ENDLOOP; END;
OUT -> Oracle_03.sql
CREATEORREPLACEPROCEDURE P3 ()RETURNSVARCHARLANGUAGESQLCOMMENT = '{"origin":"sf_sc","name":"snowconvert","version":{"major":1, "minor":0},"attributes":{"component":"oracle"}}'
EXECUTEASCALLERAS$$BEGIN !!!RESOLVE EWI!!! /*** SSC-EWI-OR0100 - FOR LOOP WITH MULTIPLE CONDITIONS IS CURRENTLY NOT SUPPORTED BY SNOWFLAKE SCRIPTING ***/!!!
FOR i IN REVERSE 1TO3LOOPNULL;ENDLOOP;END;$$;
4. FOR LOOP with unsupported format
IN -> Oracle_04.sql
CREATEORREPLACEPROCEDURE P3ASTYPE values_aat ISTABLE OF PLS_INTEGER INDEXBY PLS_INTEGER;l_employee_values values_aat;BEGINFOR power INREPEAT power*2WHILE power <=64LOOPNULL;ENDLOOP;FOR i INVALUES OF l_employee_values LOOPNULL;ENDLOOP; END;
OUT -> Oracle_04.sql
CREATEORREPLACEPROCEDURE P3 ()RETURNSVARCHARLANGUAGESQLCOMMENT = '{"origin":"sf_sc","name":"snowconvert","version":{"major":1, "minor":0},"attributes":{"component":"oracle"}}'
EXECUTEASCALLERAS$$DECLARE-- !!!RESOLVE EWI!!! /*** SSC-EWI-0058 - FUNCTIONALITY FOR 'PL COLLECTION TYPE DEFINITION' IS NOT CURRENTLY SUPPORTED BY SNOWFLAKE SCRIPTING ***/!!!
-- TYPE values_aat IS TABLE OF PLS_INTEGER INDEX BY PLS_INTEGER; l_employee_values VARIANT !!!RESOLVE EWI!!! /*** SSC-EWI-0062 - CUSTOM TYPE 'values_aat' USAGE CHANGED TO VARIANT ***/!!!;
BEGIN !!!RESOLVE EWI!!! /*** SSC-EWI-OR0103 - FOR LOOP FORMAT IS CURRENTLY NOT SUPPORTED BY SNOWFLAKE SCRIPTING ***/!!!!!!RESOLVE EWI!!! /*** SSC-EWI-OR0101 - FOR LOOP WITH "WHILE" CLAUSE IS CURRENTLY NOT SUPPORTED BY SNOWFLAKE SCRIPTING ***/!!!
FOR power INREPEAT power*2WHILE power <=64LOOPNULL;ENDLOOP; !!!RESOLVE EWI!!! /*** SSC-EWI-OR0103 - FOR LOOP FORMAT IS CURRENTLY NOT SUPPORTED BY SNOWFLAKE SCRIPTING ***/!!!
FOR i INVALUES OF :l_employee_values LOOPNULL;ENDLOOP;END;$$;
Transformation for custom types is currently not supported for Snowflake Scripting.
Known Issues
1. For With Multiple Conditions
Oracle allows multiple conditions in a single FOR LOOP however, Snowflake Scripting only allows one condition per FOR LOOP. Only the first condition is migrated and the others are ignored during transformation. Check SSC-FDM-OR0022.
FOR i IN REVERSE 1..3,REVERSE i+5..i+7LOOPNULL;ENDLOOP;
--** SSC-FDM-OR0022 - FOR LOOP WITH MULTIPLE CONDITIONS IS CURRENTLY NOT SUPPORTED BY SNOWFLAKE SCRIPTING **FOR i IN REVERSE 1TO3LOOPNULL;ENDLOOP;
2. Mutable vs Inmutable Counter Variable
Oracle allows modifying the value of the FOR LOOP variable inside the loop. The current documentation includes this functionality but Snowflake recommends avoiding this. Modifying the value of this variable may not behave correctly in Snowflake Scripting.
3. Integer vs Float number for Upper or Lower Bound
Snowflake Scripting only allows an INTEGER or an expression that evaluates to an INTEGER as a bound for the FOR LOOP condition. Floating numbers will be rounded up or down and alter the original bound. Check SSC-EWI-OR0102.
4. Oracle Unsupported Clauses
Oracle allows additional clauses to the FOR LOOP condition. Like the BY clause for a stepped increment in the condition. And the WHILE and WHEN clause for boolean expressions. These additional clauses are not supported in Snowflake Scripting and are ignored during transformation. Check SSC-EWI-OR0101.
FOR i IN5..15BY5LOOPNULL;ENDLOOP;
!!!RESOLVE EWI!!! /*** SSC-EWI-OR0101 - FOR LOOP WITH "BY" CLAUSE IS CURRENTLY NOT SUPPORTED BY SNOWFLAKE SCRIPTING ***/!!!
FOR i IN5TO15LOOPNULL;ENDLOOP;
5. Unsupported Formats
Oracle allows different types of conditions for a FOR LOOP. It supports boolean expressions, collections, records... However, Snowflake scripting only supports FOR LOOP with defined integers as bounds. All other formats are marked as not supported and require additional manual effort to be transformed. Check SSC-EWI-OR0103.
Related EWIs
SSC-EWI-0058: Functionality is not currently supported by Snowflake Scripting.
SSC-EWI-0062: Custom type usage changed to variant.
SSC-EWI-OR0100: For Loop With Multiple Conditions Is Currently Not Supported By Snowflake Scripting. Only First Condition Is Used.
SSC-EWI-OR0101: Specific For Loop Clause Is Currently Not Supported By Snowflake Scripting.
SSC-EWI-OR0103: For Loop Format Is Currently Not Supported By Snowflake Scripting.