ERROR 1064 (42000): 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 'select 1 from user_info where user_id = p_user_id))THEN select 'Username Exits !' at line 3
CREATE PROCEDURE `sp_create_user`(IN p_user_id varchar(20),IN p_user_pw varchar(20))
BEGIN
IF (select exits (select 1 from user_info where user_id = p_user_id))THEN select 'Username Exits !!';
答案 0 :(得分:1)
首先是根据您的select()
条件删除IF
,然后将exits
更改为exists
。
DELIMITER //
CREATE PROCEDURE sp_create_user( IN p_email varchar(80), IN p_username varchar(45), IN p_password varchar(45))
BEGIN
IF (exists (select 1 from user where username = p_username))
THEN select 'Username Exists !!';
ELSE
insert into user (email, username, password) values (p_email, p_username, p_password);
END IF;
END //
尝试DBFIDDLE