MariaDB在创建过程时显示错误

时间:2018-09-08 18:45:43

标签: mysql xampp mariadb

Maria DB(Xampp)在执行以下代码时显示错误:

代码:

   DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_createUser`(
    IN p_name VARCHAR(20),
    IN p_username VARCHAR(20),
    IN p_password VARCHAR(20)
)
BEGIN
    if ( select exists (select 1 from tbl_user where user_username = p_username) ) THEN

        select 'Username Exists !!';

    ELSE

        insert into tbl_user
        (
            user_name,
            user_username,
            user_password
        )
        values
        (
            p_name,
            p_username,
            p_password
        );

    END IF;
END$$
DELIMITER ;

错误:

  

#1064-您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册以获取正确的语法,以在第9行的''附近使用

1 个答案:

答案 0 :(得分:0)

我无法重现该问题:

MariaDB [_]> DROP PROCEDURE IF EXISTS `sp_createUser`;
Query OK, 0 rows affected (0.001 sec)

MariaDB [_]> DELIMITER $$

MariaDB [_]> CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_createUser`(
    ->   IN `p_name` VARCHAR(20),
    ->   IN `p_username` VARCHAR(20),
    ->   IN `p_password` VARCHAR(20)
    -> )
    -> BEGIN
    ->   IF ( select exists
    ->          (select 1
    ->           from tbl_user
    ->           where user_username = p_username) ) THEN
    ->     SELECT 'Username Exists !!';
    ->   ELSE
    ->     INSERT INTO `tbl_user`
    ->     (
    ->         `user_name`,
    ->         `user_username`,
    ->         `user_password`
    ->     )
    ->     VALUES
    ->     (
    ->         `p_name`,
    ->         `p_username`,
    ->         `p_password`
    ->     );
    ->     END IF;
    -> END$$
Query OK, 0 rows affected (0.000 sec)

MariaDB [_]> DELIMITER ;