错误1064(42000):您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册

时间:2019-10-11 01:59:19

标签: mysql mariadb

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 !!';

1 个答案:

答案 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