on 2018 Feb 28 4:58 PM
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;
Request clarification before answering.
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;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That is actually the definition of a "compound statement"... a BEGIN ... END.
User | Count |
---|---|
62 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.