mySql 错误 #2014 - 设置 FOREIGN_KEY_CHECKS = ON; - 命令不同步;您现在无法运行此命令

问题描述 投票:0回答:1

我在 stackoverflow 上阅读了很多关于此错误的帖子,但找不到我的答案。 我已经通过共享服务器上的 phpMyAdmin 在 MySQL 8.0 Standard 上创建了此过程:

DELIMITER //
CREATE PROCEDURE CreateUpdateCarrierRange (
    IN idCarrier INT,
    IN idZone INT,
    IN iWeightMin DECIMAL,
    IN iWeightMax DECIMAL,
    IN price DECIMAL,
    IN display INT
)
BEGIN
    SET @iCount :=  0;
    SELECT @iCount, idCarrier, iWeightMin, iWeightMax;
    -- Est-ce que la plage existe ? → count retourne une valeur > 0
    SELECT @iCount := COUNT(RANGE_WEIGHT.id_carrier)
    FROM range_weight as RANGE_WEIGHT
    WHERE
        RANGE_WEIGHT.id_carrier = idCarrier 
        AND RANGE_WEIGHT.delimiter1 = iWeightMin 
        AND RANGE_WEIGHT.delimiter2 = iWeightMax;
    
    IF display = 1 THEN
        SELECT @iCount as 'Nombre enregistrements range_weight';
    END IF;

END //

DELIMITER ;

我像这样调用 phpMyAdmin 我的存储过程:

CALL CreateUpdateCarrierRange(128, 1, 4.000, 5.000, 10.75, 1) 

但我收到错误

Static Analysis :

1 error found during the analysis

**Missing expression. (near "ON" at position 25)
SET FOREIGN_KEY_CHECKS = ON;
#2014 - Commands out of sync; you can't run this command now**

在我读过的帖子中,他们谈到缺少 BEGIN END、缺少分隔符、多线程(对于 1 个查询??)、... 我一定是写错了,但我没看到...

感谢您的帮助。

phpMyAdmin 中的

SHOW CREATE PROCEDURE CreateUpdateCarrierRange;
返回以下内容:

Procedure : CreateUpdateCarrierRange
**sql_mode :
Create Procedure : CREATE DEFINER=o13084985@% PROCEDURE CreateUpdateCarrierRange
haracter_set_client : utf8mb4
collation_connection : utf8mb4_unicode_ci
Database Collation : utf8mb4_general_ci 
mysql synchronization command out
1个回答
0
投票

您可以尝试以下操作并检查是否有帮助。

我尝试用声明变量替换 SET,以消除在调用过程的上下文中 SET 或会话更改命令(如 SET FOREIGN_KEY_CHECKS = ON)发生冲突的可能性

DELIMITER //

CREATE PROCEDURE CreateUpdateCarrierRange (
    IN idCarrier INT,
    IN idZone INT,
    IN iWeightMin DECIMAL,
    IN iWeightMax DECIMAL,
    IN price DECIMAL,
    IN display INT
)
BEGIN
    DECLARE iCount INT DEFAULT 0;

    -- Check if the range exists
    SELECT COUNT(RANGE_WEIGHT.id_carrier)
    INTO iCount
    FROM range_weight AS RANGE_WEIGHT
    WHERE RANGE_WEIGHT.id_carrier = idCarrier 
    AND RANGE_WEIGHT.delimiter1 = iWeightMin 
    AND RANGE_WEIGHT.delimiter2 = iWeightMax;

    -- If display is set to 1, show the count of records in range_weight
    IF display = 1 THEN
        SELECT iCount AS 'Nombre enregistrements range_weight';
    END IF;

    -- Optionally, you could add logic here to insert or update records in range_weight based on iCount.
END //

DELIMITER ;
© www.soinside.com 2019 - 2024. All rights reserved.