我一直在尝试在mysql中创建此过程,但它始终会输出相同的错误
CREATE PROCEDURE registrarCuenta(@username, @password, @salt, @email)
BEGIN
INSERT INTO (`Usuarios` `username`, `password`, `salt`, `email`) VALUES (@username, @password, @salt, @email)
SET @code := lpad(conv(floor (rand()*pow(36,10)), 10, 36), 10, 0)
WHILE(EXISTS(SELECT * FROM `Activaciones` WHERE `code` = @code))
BEGIN
SET @code := lpad(conv(floor(rand()*pow(36,10)), 10, 36), 10, 0)
END
BEGIN
INSERT INTO `Activaciones` (`code`) VALUES (@code)
END
END
GO;
答案 0 :(得分:0)
由于您正在使用命令GO
,因此我猜想您想在TSQL
中实现该过程。这是您的代码中的一些错误:
CREATE PROCEDURE registrarCuenta
(
@username NVARCHAR(255),
@password NVARCHAR(255),
@salt NVARCHAR(255),
@email NVARCHAR(100)
)
AS
BEGIN
DECLARE code FLOAT(5,2); -- or whatever you like
INSERT INTO `Usuarios` (`username`, `password`, `salt`, `email`) VALUES
(@username, @password, @salt, @email);
SET @code = lpad(conv(floor (rand()*pow(36,10)), 10, 36), 10, 0);
WHILE(EXISTS(SELECT * FROM `Activaciones` WHERE `code` = @code)) -- not sure if this is correct
BEGIN
SET @code = lpad(conv(floor(rand()*pow(36,10)), 10, 36), 10, 0);
END
INSERT INTO `Activaciones` (`code`) VALUES (@code);
END
GO;
或者如果您确实想要MySQL:
DELIMITER $$
CREATE PROCEDURE registrarCuenta
(
IN username VARCHAR(255),
IN password VARCHAR(255),
IN salt VARCHAR(255),
IN email VARCHAR(100)
)
AS
BEGIN
DECLARE code FLOAT(5,2); -- or whatever you like
INSERT INTO `Usuarios` (`username`, `password`, `salt`, `email`) VALUES
(@username, @password, @salt, @email);
SET @code = lpad(conv(floor (rand()*pow(36,10)), 10, 36), 10, 0);
WHILE(EXISTS(SELECT * FROM `Activaciones` WHERE `code` = @code)) DO -- not sure if this is correct
SET @code = lpad(conv(floor(rand()*pow(36,10)), 10, 36), 10, 0);
END WHILE;
INSERT INTO `Activaciones` (`code`) VALUES (@code);
END$$
DELIMITER ;
随时向您说明您要实施的过程,以便获得其他支持!