gpt4 book ai didi

mysql - MariaDB 在创建过程时显示错误

转载 作者:行者123 更新时间:2023-11-29 17:01:13 25 4
gpt4 key购买 nike

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 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 9

最佳答案

我无法重现该问题:

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 ;

关于mysql - MariaDB 在创建过程时显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52238361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com