1

I have an error in while and end while in my code ... here is my code:

SET i = 0;
WHILE i<n DO
INSERT INTO bo_search_engine_scenario (version, mcs, name, factor, tracking_code) 
          SELECT version, mcs, name, factor, tracking_code FROM  bo_search_engine_scenario_temp LIMIT i,1;
END WHILE

Why does it give me while is not valid at this position?

4
  • is this inside a Stored procedure ? Commented Jul 4, 2016 at 12:44
  • nop it is not inside procedure Commented Jul 4, 2016 at 12:46
  • I don't understand what you want to do. SQL Fiddle demo using WHILE. Commented Jul 4, 2016 at 13:14
  • You can't just type any old command anywhere and expect it to work. Commented Jul 4, 2016 at 14:49

1 Answer 1

3

You cannot use a while loop outside of a stored procedure.

https://dev.mysql.com/doc/refman/5.7/en/while.html

There is an example on the documentation. A quick Google search will also give you plenty of information on stored procedures.

Sign up to request clarification or add additional context in comments.

3 Comments

also i tried now using procedure and the same errors appear
Can you please post the procedure you attempted
That is a stupid restriction! I was trying to test something in a regular query window; I should not have to create a dummy proc first to testing something.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.