unyeol
unyeol

Reputation: 57

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version

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

Upvotes: 1

Views: 1145

Answers (1)

Ed Bangga
Ed Bangga

Reputation: 13006

First is to remove select() on your IF condition, second change exits to 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 //

Try DBFIDDLE

Upvotes: 1

Related Questions