Beginner While loop error in MySQL -
i have looked @ various guides on mysql while loops , still can't figure out doing wrong.
mysql> delimiter $$ mysql> create procedure insertrooms() -> begin -> declare nroom int default 101; -> while nroom < 109 -> insert simple_room (room_number) values nroom; -> set nroom = nroom + 1; -> end while; -> end; -> $$ error 1064 (42000): have error in sql syntax; check manual corresponds mysql server version right syntax use near 'nroom ; set nroom = nroom + 1; end while; end' @ line 5
i trying while loop insert rooms 101 - 108 simple_room table. appreciated, have tried searching on google , stackoverflow , not find why keep getting syntax error. using mysql version 5.6.24.
your query correct except forgot using brackets around nromm
. try this,
mysql> delimiter $$ mysql> create procedure insertrooms() -> begin -> declare nroom int default 101; -> while nroom < 109 -> insert simple_room (room_number) values(nroom); -> set nroom = nroom + 1; -> end while; -> end; -> $$
hope helps, thanks.
Comments
Post a Comment