gpt4 book ai didi

MySQL - 你的 SQL 语法有错误;检查与您的 MariaDB 服务器版本对应的手册以了解正确的语法 - phpMyAdmin

转载 作者:太空宇宙 更新时间:2023-11-03 10:30:59 26 4
gpt4 key购买 nike

我在 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 ;

但它一直显示错误:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DECLARE v_IsOTPValid TINYINT DEFAULT NULL; SET v_IsOTPValid = NULL; DECL' at line 9

我试过:

Is declare in mysql giving syntax error?

Mystery error in CREATE PROCEDURE in MariaDB/MySQL

但这些答案都没有帮助!

最佳答案

您在所有 DECLARE 语句结束之前有一个 SET..

并根据 official documentation , 将所有 declare 放在 set 或任何其他语句之前:

BEGIN   
DECLARE v_IsOTPValid TINYINT DEFAULT NULL;
DECLARE v_userCode CHAR(36);
DECLARE v_Token CHAR(36);
SET v_IsOTPValid = NULL;

关于MySQL - 你的 SQL 语法有错误;检查与您的 MariaDB 服务器版本对应的手册以了解正确的语法 - phpMyAdmin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58571886/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com