In today’s article, we will be learning the Loop Statements, one of the plgpsql commands that helps us perform operations between the given values.
Although this command sometimes makes operations easier, it can cause problems when we do not use the exit command.
That’s why we need to pay attention to logical errors and our circumstances.
General Usage is as follows.
1 2 3 4 5 6 7 | LOOP condition; Exit when condition ends\completion. End loop; |
If we want to print the numbers from 1 to 5 one under the other as 1st Loop value….5 Loop value, we can use the command below.
1 2 3 4 5 6 7 8 9 10 | DO $$ DECLARE sayi int := 1; begin LOOP RAISE NOTICE '%. Loop değeri ', sayi; sayi := sayi + 1; EXIT WHEN sayi = 6; END LOOP; end $$ |