在存储过程中是否存在其他问题

时间:2019-06-13 06:47:02

标签: mysql

如果在存储过程中,我正在使用if else 但是会产生错误

  

错误代码:1064       您的SQL语法有误;检查与您的MariaDB服务器版本相对应的手册以使用正确的语法   在“ SELECT'0”响应代码附近,“请输入年龄!!!” responseMessage;           第35行的ELSEIF IFNUL'

我不知道我的程序在哪里出现语法错误

DELIMITER $$

CREATE
    /*[DEFINER = { user | CURRENT_USER }]*/
    PROCEDURE `saathi`.`proc_test`(
    p_nameAlias VARCHAR(50),
    p_age VARCHAR(50),
    p_dob DATE,
    p_gender VARCHAR(50),
    p_email VARCHAR(50),
    p_occupation VARCHAR(50),
    p_educationLevel VARCHAR(50),
    p_userName VARCHAR(50),
    p_password VARCHAR(50),
    p_district INT(11),
    p_state INT(11),
    p_placeofOrigin VARCHAR(50),
    p_mobile VARCHAR(50),
    p_maritalStatus VARCHAR(50),
    p_behaviour VARCHAR(50),
    p_hydc VARCHAR(50)
    )
    /*LANGUAGE SQL
    | [NOT] DETERMINISTIC
    | { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
    | SQL SECURITY { DEFINER | INVOKER }
    | COMMENT 'string'*/
    BEGIN
      IF IFNULL(P_nameAlias,'')=''
    THEN
    SELECT '0' responseCode, 'Please enter name!!!' responseMessage;

    ELSEIF IFNULL(p_dob,'')=''
    THEN
    SELECT '0' responseCode, 'Please enter dob!!!' responseMessage;
    ELSEIF IFNULL(p_age,'')=''
    SELECT '0' responseCode,'Please enter age!!!'  responseMessage;
    ELSEIF IFNULL(p_gender,'')=''
    THEN
    SELECT '0' responseCode,'Please enter gender!!!' responseMessage;

    ELSE 
    SELECT '200' responseCode,'Tested' responseMessage;

    END IF;
    END IF;
    END IF;
    END IF;

    END$$

应该可以成功编译

1 个答案:

答案 0 :(得分:1)

ELSE和IF

之间应该有一个空格

ELSEIF更改为ELSE IF

THEN之后放置IFNULL(p_age,'')=''