Trying to run a loop statement, but it fails at the first line with - Variable 'i' not found. Do I need to define this first somehow? Thanks SET i = 203; WHILE i <= 264 LOOP SELECT Cust_Name AS RC_Name FROM Customers WHERE Customer_ID = i ; --- INSERT STATEMENTS --- SET i = i + 1; END LOOP; |
Hi, you need to declare or create it first: CREATE VARIABLE i INTEGER; Alternatively, you will need to declare it, but then you will need to use compound statement: BEGIN DECLARE i INTEGER; --YOUR CODE-- END; Compound statement?
(28 Feb '18, 18:17)
gchq
You probably don't want that first one -- that creates a connection-scope variable that persists until your connection is dropped or you explicitly drop the variable.
(28 Feb '18, 18:19)
John Smirnios
Using CREATE VARIABLE throws - Syntax error near 'SET'
(28 Feb '18, 18:20)
gchq
Using BEGIN and END; (Compound Statement??) works - thank you
(28 Feb '18, 18:23)
gchq
Replies hidden
2
That is actually the definition of a "compound statement"... a BEGIN ... END.
(01 Mar '18, 07:22)
Breck Carter
We have an isolated existence here :-) Will try to remember that.
(02 Mar '18, 18:48)
gchq
Oh! Now I know the new term! Thank you Breck!
(03 Mar '18, 10:48)
Vlad
|