有人能指出我为什么会有语法错误吗?每当我尝试将其输入控制台时,我都会得到“expre2”的语法错误,但我没有得到,因为它看起来很好:
DELIMITER $$
DROP PROCEDURE IF EXISTS `add_User`$$
CREATE PROCEDURE `add_User`(IN `p_Name` VARCHAR(45), IN `p_Passw` VARCHAR(200), IN NIF INT(12))
BEGIN
DECLARE `_HOST` CHAR(14) DEFAULT '@\'localhost\'';
SET `p_Name` := CONCAT('\'', REPLACE(TRIM(`p_Name`), CHAR(39), CONCAT(CHAR(92), CHAR(39))), '\''),
`p_Passw` := CONCAT('\'', REPLACE(`p_Passw`, CHAR(39), CONCAT(CHAR(92), CHAR(39))), '\'');
SET @`sql` := CONCAT('CREATE USER ', `p_Name`, `_HOST`, ' IDENTIFIED BY ', `p_Passw`);
PREPARE `stmt` FROM @`sql`;
EXECUTE `stmt`;
DEALLOCATE PREPARE `stmt`;
FLUSH PRIVILEGES;
SET @`expre` := CONCAT('GRANT SELECT, INSERT, UPDATE ON trabalho.ver_assist TO ', `p_Name`);
PREPARE `stmt2` FROM @`expre`;
EXECUTE `stmt2`;
DEALLOCATE `stmt2`;
SET @`expre2` := CONCAT('GRANT SELECT, INSERT, UPDATE ON trabalho.ver_saidas TO ', `p_Name`);
PREPARE `stmt3` FROM @`expre2`;
EXECUTE `stmt3`;
DEALLOCATE `stmt3`;
FLUSH PRIVILEGES;
END$$
我真的不明白为什么它不起作用。。。
2条答案
按热度按时间ql3eal8s1#
你错过了一个
PREPARE
在DEALLOCATE stmt2
以及DEALLOCATE stmt3
也。请在下面找到正确的查询:jm2pwxwz2#
您的set语句不正确,您必须选择set@sql:=(select concat('create user',
p_Name
,_HOST
,'标识人',p_Passw
));你的2个deallocate是不正确的语法是deallocate prepare something
而且里面有很多不必要的背勾。