MySQL syntax for UPDATE with IF conditional expression in stored procedure?

I am trying to start a stored procedure, but its retrieval failed due to a condition IF. I tried in many ways until I succeeded. can anyone tell me how to use the IF condition in a stored procedure.

DELIMITER $$

USE `testdb`$$

DROP PROCEDURE IF EXISTS `change_parent`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `change_parent`(
    IN new_parent BIGINT(20),
    IN folder__id BIGINT(20)
)
BEGIN
    SELECT 
        directory_path,nav_depth,id
    INTO 
        @dirpath,@depth,@parent
    FROM folders 
    WHERE id = new_parent;
    UPDATE folders


        IF (folder__id != @parent) THEN 
        SET     directory_path = CONCAT(@dirpath,'/',title),
            nav_depth = @depth+1,
            parent__id = @parent
        END IF;
    WHERE id = folder__id;

END$$

DELIMITER ;

Here is the error message

Error code: 1064 You have an error in the syntax of SQL; check the manual that matches the version of your MySQL server for the correct syntax:'IF folder__id != @parent THEN SET directory_path = CONCAT(@dirpath,'/',title' at line 13

+4
source share
1 answer
IF (folder__id != @parent) THEN
    UPDATE folders
            SET ...
        WHERE id = folder__id;
END IF;
0
source

All Articles