I am trying to write one function with IF and I am getting Error
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ” at line 8 Code 1064
This is the function.
DELIMITER $$
DROP FUNCTION IF EXISTS `my_fun` $$
CREATE FUNCTION `my_fun` (nid INT) RETURNS VARCHAR(200)
BEGIN
DECLARE abc varchar(100);
SELECT foo INTO abc FROM my_table WHERE bar = nid;
IF abc = ''
THEN
SELECT foo INTO abc FROM my_table WHERE bar = -1;
RETURN abc;
END $$
DELIMITER ;
Am not sure whats the syntax here , I tried IF abc IS NULL also.
I just want to check if first select statement returned empty value then execute another statement.
You’re missing
END IFstatement.Your code should be: