有人可以指出为什么我遇到语法错误吗?每当我尝试将其输入到控制台中时,都会收到“ 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$$
我真的不明白为什么它不起作用...
答案 0 :(得分:1)
您的set语句不正确,您必须选择例如SET @sql:=(选择CONCAT('CREATE USER',p_Name
,_HOST
,'IDENTIFIED BY',p_Passw
));
您的dealloc的2个错误,语法为dealloc的准备一些东西
那里有很多不必要的反引号。
答案 1 :(得分:0)
您在PREPARE
和DEALLOCATE stmt2
中分别是missing和DEALLOCATE stmt3
。请在更正的查询下方找到:
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 PREPARE `stmt2`;
SET @`expre2` := CONCAT('GRANT SELECT, INSERT, UPDATE ON trabalho.ver_saidas TO ', `p_Name`);
PREPARE `stmt3` FROM @`expre2`;
EXECUTE `stmt3`;
DEALLOCATE PREPARE `stmt3`;
FLUSH PRIVILEGES;
END$$