我在使用 MySQL 存储过程时遇到了非常糟糕的情况,我无法在数据库中创建此过程(MySQL 5.5.27)
我想知道为什么它拒绝我的变量声明、多选和 if else(希望是一些代码错误)我正在粘贴我的代码!
DELIMITER $$
DROP PROCEDURE IF EXISTS EditEnterprise
$$
CREATE PROCEDURE EditEnterprise(
IN pEnterpriseId VARCHAR(32),
IN pEnterpriseName VARCHAR(64)
)
/* declare the new variables */
DECLARE nEnterpriseId VARCHAR(32);
DECLARE nEnterpriseName VARCHAR(64);
/* declare the old variables */
DECLARE oEnterpriseId VARCHAR(32);
DECLARE oEnterpriseName VARCHAR(64);
BEGIN
SET autocommit = 0;
/* get the old variables */
SELECT
Enterprise_ID = oEnterpriseId,
Enterprise_Name = oEnterpriseName
FROM
enterprise
WHERE
Enterprise_ID = pEnterpriseId;
/* set the variables with the new inputs */
IF pEnterpriseName = NULL
SET nEnterpriseName = oEnterpriseName
ELSE IF pEnterpriseName = ''
SET oEnterpriseName = NULL
ELSE
SET nEnterpriseName = pEnterpriseName
UPDATE enterprise
SET
Enterprise_Name = nEnterpriseName
WHERE Enterprise_ID = pEnterpriseId;
COMMIT;
END $$
DELIMITER ;