How to use loops in teradata?

by ryan.murray , in category: MySQL , 19 days ago

How to use loops in teradata?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by tressie.damore , 18 days ago

@ryan.murray 

To use loops in Teradata, you can make use of the REPEAT, WHILE, and FOR loops.

  1. REPEAT loop:
1
2
3
4
5
6
SET i = 1;
REPEAT
  ...
  SET i = i + 1;
UNTIL i > 10
END REPEAT;


  1. WHILE loop:
1
2
3
4
5
SET i = 1;
WHILE i <= 10 DO
  ...
  SET i = i + 1;
END WHILE;


  1. FOR loop:
1
2
3
FOR i AS 1 TO 10 DO
  ...
END FOR;


These loops can be used within a Teradata stored procedure, function, or block of SQL code to iterate over a set of statements until a certain condition is met.