LOOP

Translation reference to convert Teradata LOOP statement to Snowflake Scripting

Some parts in the output code are omitted for clarity reasons.

Description

Teradata's LOOP statement is translated to Snowflake Scripting LOOP syntax.

For more information on Teradata Loop, check here.

[label_name:] LOOP
    { sql_statement }
END LOOP [label_name];

Sample Source Patterns

Teradata

IN -> Teradata_01.sql
CREATE PROCEDURE loopProcedure(OUT resultCounter INTEGER)
BEGIN
    DECLARE counter INTEGER DEFAULT 0;
   
    customeLabel: LOOP 
    	SET counter = counter + 1;
	IF counter = 10 THEN
	    LEAVE customeLabel;
	END IF;
    END LOOP customeLabel;
   
    SET resultCounter = counter;
END;

CALL loopProcedure(:?);

Snowflake Scripting

OUT -> Teradata_01.sql
CREATE OR REPLACE PROCEDURE loopProcedure (
--                                           OUT
                                               RESULTCOUNTER INTEGER)
RETURNS VARIANT
LANGUAGE SQL
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "teradata",  "convertedOn": "07/24/2024" }}'
EXECUTE AS CALLER
AS
$$
	DECLARE
		counter INTEGER DEFAULT 0;
	BEGIN
		 
		LOOP
			counter := counter + 1;
			IF (counter = 10) THEN
				BREAK CUSTOMELABEL;
			END IF;
		END LOOP CUSTOMELABEL;
		resultCounter := counter;
		RETURN resultCounter;
	END;
$$;

CALL loopProcedure(:?);

Known Issues

No issues were found.

No related EWIs.

Last updated