n4mi n4mi - 2 months ago 18
MySQL Question

what is mysql stored procedure if statement structure

CREATE PROCEDURE PROCEDURENAME()
BEGIN
IF ((CONDITION),SELECT 0, SELECT 1)); //not working
IF condition THEN statement END IF; //not working
IF condition
statement //not working
END


How should I properly write the if statement structure? Anyone have a working example? Please help me.

Answer

Clearly read the last stored procedure structure on the below page

http://www.mysqltutorial.org/mysql-if-statement/

please use your code like this one or simply put your code and condition in below code so I will make it fix

DELIMITER //

CREATE PROCEDURE `proc_IF` (IN param1 INT)
BEGIN
    DECLARE variable1 INT;
    SET variable1 = param1 + 1;

    IF variable1 = 0 THEN
        SELECT variable1;
    END IF;

    IF param1 = 0 THEN
        SELECT 'Parameter value = 0';
    ELSE
        SELECT 'Parameter value <> 0';
    END IF;
END //