当前位置: 首页 > 知识库问答 >
问题:

MySQL-您的SQL语法中有一个错误;检查与您的MariaDB服务器版本相对应的手册以获得正确的语法-phpMyAdmin

索锐藻
2023-03-14

我正在phpMyAdmin中的存储过程下面运行:

DELIMITER //

CREATE PROCEDURE usp_ForgotPassword (
    -- Add the parameters for the stored procedure here
    p_mobileNo VARCHAR(50),
    p_emailId VARCHAR(300),
    p_password VARCHAR(300),
    p_otp VARCHAR(50),
    p_appInstanceCode CHAR(36))
BEGIN   
    DECLARE v_IsOTPValid TINYINT DEFAULT  NULL;
    SET v_IsOTPValid = NULL;
    DECLARE v_userCode CHAR(36);

    IF (v_IsOTPValid = 1)
    THEN
        IF EXISTS(SELECT * FROM OTP WHERE otp = p_otp AND mobileNo = p_mobileNo)
        THEN

            SET v_userCode = (SELECT userCode FROM UserLogin WHERE userName = p_emailId);

            UPDATE UserLogin UL
            SET password = p_password 
            WHERE userName = p_emailId AND userCode = v_userCode;

            -- Delete the verified OTP 
            DELETE FROM OTP WHERE otp = p_otp AND mobileNo = p_mobileNo;

            DECLARE v_Token CHAR(36);


            INSERT INTO Token (createdAt, updatedAt,code,userCode,appInstanceCode,deviceIMEI,deviceName)
                                VALUES (NOW(),NOW(),v_Token,v_userCode,p_appInstanceCode,NULL,NULL);


            SELECT 200 code, 'Password changed succesfully' as message,v_Token;
        ELSE
            SELECT 400 as code, 'Invalid OTP or Mobile No' as message,v_Token;
        END IF;
    ELSE
        SELECT 401 as code, 'OTP expired' as message,v_Token;
    END IF; 
END
//
delimiter ;

Mariadb/MySQL创建过程中的神秘错误

但这些答案都无济于事!

共有1个答案

龙枫
2023-03-14

在所有DECLARE语句结束之前都有一个集合。

根据官方文档,将所有declare放在set或任何其他语句之前:

BEGIN   
  DECLARE v_IsOTPValid TINYINT DEFAULT  NULL;
  DECLARE v_userCode CHAR(36);
  DECLARE v_Token CHAR(36); 
  SET v_IsOTPValid = NULL; 
 类似资料: