MariaDB在创建过程时显示错误

问题描述 投票:0回答:1

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行的''附近使用正确的语法

mysql xampp mariadb
1个回答
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 ;
© www.soinside.com 2019 - 2024. All rights reserved.