MySQL: Error code: 1064 while creating procedure
I cannot find how to fix my problem, Here is my code:
DELIMITER //
CREATE procedure SP_INS_fbUSER
(v_email varchar(50), v_password varchar(20), v_first_name Nvarchar(20),
v_last_name Nvarchar(20), v_full_name Nvarchar(50), v_profile_pic_arr text)
BEGIN
IF(exists(SELECT * FROM USER WHERE email = v_email)) then
BEGIN
INSERT INTO USER
(email,password,first_name,last_name,full_name,active,profile_pic_arr)
VALUES
(v_email,v_password,v_first_name,v_last_name,v_full_name,TRUE,v_profile_pic_arr);
END IF;
end;
DELIMITER ;
And here is the error message:
Error code: 1064. You have an error in your SQL syntax; check the manual corresponding to your MySQL server version for the correct syntax to use next to '' on line 10
what's the problem on line 10 and how to fix it?
I tried this code:
DELIMITER //
CREATE procedure SP_INS_fbUSER
(v_email varchar(50), v_password varchar(20), v_first_name Nvarchar(20),
v_last_name Nvarchar(20), v_full_name Nvarchar(50), v_profile_pic_arr text)
BEGIN
IF(exists(SELECT * FROM USER WHERE email = v_email)) then
BEGIN
INSERT INTO USER
(email,password,first_name,last_name,full_name,active,profile_pic_arr)
VALUES
(v_email,v_password,v_first_name,v_last_name,v_full_name,TRUE,v_profile_pic_arr);
END
--------^
END IF;
end;
DELIMITER ;
But it still shows the same error. Then I try this code:
DELIMITER //
CREATE procedure SP_INS_fbUSER
(v_email varchar(50), v_password varchar(20), v_first_name Nvarchar(20),
v_last_name Nvarchar(20), v_full_name Nvarchar(50), v_profile_pic_arr text)
BEGIN
IF(exists(SELECT * FROM `USER` WHERE `email` = v_email)) then
BEGIN
INSERT INTO `USER`
(`email`,`password`,`first_name`,`last_name`,`full_name`,`active`,`profile_pic_arr`)
VALUES
(v_email,v_password,v_first_name,v_last_name,v_full_name,TRUE,v_profile_pic_arr);
END
END IF;
END//
DELIMITER ;
And it shows:
Error code: 1064. You have an error in your SQL syntax.
check the manual corresponding to your MySQL server version for the correct syntax to use next to END IF; END 'on line 12
Can anyone help me please?
+3
source to share
2 answers
Try the following:
DELIMITER //
CREATE procedure SP_INS_fbUSER
(v_email varchar(50), v_password varchar(20), v_first_name Nvarchar(20),
v_last_name Nvarchar(20), v_full_name Nvarchar(50), v_profile_pic_arr text)
BEGIN
IF (EXISTS(SELECT * FROM `USER` WHERE `email` = v_email)) THEN
INSERT INTO `USER`
(`email`,`password`,`first_name`,`last_name`,`full_name`,`active`,`profile_pic_arr`)
VALUES
(v_email,v_password,v_first_name,v_last_name,v_full_name,TRUE,v_profile_pic_arr);
END IF;
END //
DELIMITER ;
0
source to share
You don't have END
for your BEGIN
:
DELIMITER //
CREATE procedure SP_INS_fbUSER
(v_email varchar(50), v_password varchar(20), v_first_name Nvarchar(20),
v_last_name Nvarchar(20), v_full_name Nvarchar(50), v_profile_pic_arr text)
BEGIN
IF(exists(SELECT * FROM USER WHERE email = v_email)) then
BEGIN
INSERT INTO USER
(email,password,first_name,last_name,full_name,active,profile_pic_arr)
VALUES
(v_email,v_password,v_first_name,v_last_name,v_full_name,TRUE,v_profile_pic_arr);
END
--------^
END IF;
end//
DELIMITER ;
0
source to share