我似乎无法在此过程中声明变量

I can't seem to declare variables inside this procedure

我无法让这段代码工作,我不断收到语法错误,而且我没有发现声明语句有任何问题。

    delimiter //
    create procedure Plsql1 (Count int)
        begin


            CREATE TABLE alumnos(
                nombre VARCHAR(7) primary key,
                edad INT (7),
                sexo INT (2));

            DECLARE Count int default 10;
            DECLARE Number int default 0;
            DECLARE done int = 0;

            etiq1: loop
                if not done then
                    INSERT INTO alumnos VALUES(CONCAT('Victor',Number), Number*5, Number%2);
                    SET N=N+1;

                    if (Number=Count) SET done=1;
                else
                    leave etiq1;
                end if;
            end loop;

            SELECT * FROM alumnos;
        end //
delimiter ;

当我尝试让它工作时,我得到了这个:

ERROR 1064 (42000): 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 'DECLARE Count int default 10;
        DECLARE Number int default 0;
        DECL' at line 10

但是,我在那里看不到任何语法错误。请对此提出一些建议?

您可以像在存储过程中那样创建 table:

CREATE PROCEDURE procedure1(IN tableName VARCHAR(255))
BEGIN
  SET @sql = CONCAT('CREATE TABLE ', tableName, '(column1 INT(11))');
  PREPARE stmt FROM @sql;
  EXECUTE stmt;
  DEALLOCATE PREPARE stmt;
  // Do all other stuff then...
END

应该可以。