diff --git a/mysql-test/suite/compat/oracle/r/sp.result b/mysql-test/suite/compat/oracle/r/sp.result index 17d6837f85f68..47d1d1f1fa567 100644 --- a/mysql-test/suite/compat/oracle/r/sp.result +++ b/mysql-test/suite/compat/oracle/r/sp.result @@ -775,6 +775,18 @@ SELECT @v; 6 DROP PROCEDURE p1; # Testing the FOR loop statement +CREATE TABLE t1 (a INT); +FOR i IN 1 .. 3 +LOOP +INSERT INTO t1 VALUES (i); +END LOOP; +/ +SELECT * FROM t1; +a +1 +2 +3 +DROP TABLE t1; CREATE FUNCTION f1 (lower_bound INT, upper_bound INT, lim INT) RETURN INT AS total INT := 0; diff --git a/mysql-test/suite/compat/oracle/t/sp.test b/mysql-test/suite/compat/oracle/t/sp.test index 3e43741238eda..6041da34bfedc 100644 --- a/mysql-test/suite/compat/oracle/t/sp.test +++ b/mysql-test/suite/compat/oracle/t/sp.test @@ -847,6 +847,18 @@ DROP PROCEDURE p1; --echo # Testing the FOR loop statement +CREATE TABLE t1 (a INT); +DELIMITER /; +FOR i IN 1 .. 3 +LOOP + INSERT INTO t1 VALUES (i); +END LOOP; +/ +DELIMITER ;/ +SELECT * FROM t1; +DROP TABLE t1; + + DELIMITER /; --error ER_PARSE_ERROR CREATE FUNCTION f1 (lower_bound INT, upper_bound INT, lim INT) RETURN INT diff --git a/sql/sql_yacc_ora.yy b/sql/sql_yacc_ora.yy index 360f17b7f7ddd..a29fa1e5b6ff7 100644 --- a/sql/sql_yacc_ora.yy +++ b/sql/sql_yacc_ora.yy @@ -3647,6 +3647,8 @@ sp_unlabeled_control: | FOR_SYM { // See "The FOR LOOP statement" comments in sql_lex.cc + if (Lex->maybe_start_compound_statement(thd)) + MYSQL_YYABORT; Lex->sp_block_init(thd); // The outer DECLARE..BEGIN..END block } sp_for_loop_index_and_bounds