I got into a problem with the SQL IF statement. And I tried a few another statement, but it doesn’t work too.
I got my code here:
DELIMITER $
BEGIN NOT ATOMIC
IF user = 'test' THEN
SELECT fox FROM conv WHERE user = test;
ELSE
INSERT INTO pending_conv (pending) VALUES ('test');
END IF;
END $
DELIMITER ;
And the error message:
#1327 - Undeclared variable: user
I know I’m bad at this because I’m new to this. I appreciate all your anwser
>Solution :
It isn’t clear what you are attempting to do, but you could pass in a value when calling a stored procedure. Do this by adding an IN parameter to the CREATE PROCEDURE statement and give the parameter a name and data type:
DELIMITER $
CREATE PROCEDURE my_procedure(IN user VARCHAR(255))
BEGIN
IF user = 'test' THEN
SELECT fox FROM conv WHERE user = 'test';
ELSE
INSERT INTO pending_conv (pending) VALUES ('test');
END IF;
END $
DELIMITER ;
Call the stored procedure and pass a value for user like this:
CALL my_procedure('some_user');