Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WHILE Loop

Status
Not open for further replies.

Fuzemmo

Programmer
May 16, 2002
52
US
Ok, I feel stupid for having to ask this but I can't seem to make it work. I'm following what appears to be a simple example too.

SET @v1 = 5;
WHILE @v1 > 0 DO
SET @v1 = @v1 - 1;
END WHILE;

I'm betting two errors:
1.
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHILE (@v1 > 0) DO
SET @v1 = @v1 - 1' at line 1

2.
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END WHILE' at line 1

It seems that what I'm trying to do is very simple. Am I missing something incredibly simple?
 
what version of mysql are you using? THe error you are getting is that you need to upgrade your version of mysql to do this.
 
5.0.16-nt

If I'm reading the "manual" correctly, my version should be fine.
 
Ooops I should have seen, since I had similar problem with something yesterday. Did you change your delimiter to something other than the ; ? because if you didn't then each line is being read individually up until the ; is reached.

Try this:
Code:
DELIMITER $$
SET @v1 = 5;
WHILE @v1 > 0 DO
   SET @v1 = @v1 - 1;
END WHILE;

END $$

DELIMITER ;

which says for the purposes of what you are doing, ignore the ; as your delimiter and read everything together as one command until the END $$ shows up.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top