【发布时间】:2019-09-22 20:10:58
【问题描述】:
我正在尝试在 mysql/mariadb 中创建一个带有声明变量的 SP - 但我不明白,它有什么问题!?!
DROP PROCEDURE IF EXISTS UpdateReceiverDevice;
DELIMITER $$
CREATE PROCEDURE `UpdateReceiverDevice`(IN `deviceIdentifier` VARCHAR(45), IN `deviceName` VARCHAR(45), IN `deviceLocation` VARCHAR(45), IN `informations` TEXT) NOT DETERMINISTIC MODIFIES SQL DATA SQL SECURITY DEFINER
BEGIN
DECLARE receiverDeviceId AS INT(11) DEFAULT 0
SET receiverDeviceId = (SELECT ID FROM ReceiverDevice WHERE DeviceIdentifier = deviceIdentifier);
IF (receiverDeviceId > 0) BEGIN
UPDATE ReceiverDevice SET Informations = informations WHERE ID = receiverDeviceId;
ELSE
INSERT INTO ReceiverDevice (DeviceName, DeviceLocation, DeviceIdentifier, Informations) VALUES(deviceName, deviceLocation, deviceIdentifier, informations);
END IF
END $$
DELIMITER ;
MySQL 正在返回此错误:
Ein oder mehrere Fehler sind aufgetreten während Ihre Anfrage verarbeitet wurde: Die folgende Abfrage ist fehlgeschlagen: "CREATE PROCEDURE
UpdateReceiverDevice(INdeviceIdentifierVARCHAR(45), INdeviceNameVARCHAR(45), INdeviceLocationVARCHAR(45), INinformationsTEXT) 非确定性修改 SQL DATA SQL SECURITY DEFINER DECLARE receiverDeviceId AS INT(11) SET receiverDeviceId = (SELECT ID FROM ReceiverDevice WHERE DeviceIdentifier = deviceIdentifier) IF receiverDeviceId > 0 UPDATE ReceiverDevice SET Informations = informations WHERE ID = @receiverDeviceId ELSE INSERT INTO ReceiverDevice (DeviceName, DeviceLocation, DeviceIdentifier,信息) VALUES(deviceName, deviceLocation, deviceIdentifier, informations) END IF"MySQL 融合:#1064 - der SQL 语法中的 Fehler。 Bitte die korrekte Syntax im Handbuch nachschlagen bei 'DECLARE receiverDeviceId AS INT(11) SET receiverDeviceId = (SELECT ID FROM Re' in Zeile 1
这是我的服务器:
- 服务器类型:MariaDB
- 服务器版本:10.3.11-MariaDB-1:10.3.11+maria~bionic - mariadb.org 二进制分发
- Protokoll 版本:10
- 服务器-Zeichensatz:UTF-8 Unicode (utf8)
【问题讨论】:
-
每个语句都需要终止。包括声明和结束 ifs
-
BEGINs发生了什么?
标签: mysql stored-procedures mariadb