我无法使用此代码,我不断收到语法错误,并且我认为声明句子没有任何问题。
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
但是,我看不到任何语法错误。请给我一些建议吗?
答案 0 :(得分:0)
您可以在存储过程中创建类似的表:
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
这应该有效。