1
設置爲結果我想在MySQL中建立以下功能,但功能還沒有生成,但是因錯誤而失敗變量的值從SELECT語句在MySQL
DELIMITER $$
CREATE FUNCTION MapAccountType(AccountTypeID INT)
RETURNS VARCHAR(50)
DETERMINISTIC
BEGIN
DECLARE @AccountType varchar(50);
SELECT AccountType INTO @AccountType
FROM AccountType
WHERE AccountTypeID = AccountTypeID);
RETURN AccountType;
END $$
DELIMITER ;
的說明我的表
CREATE TABLE AccountType(
AccountTypeID INT AUTO_INCREMENT PRIMARY KEY,
AccountType varchar(100) UNIQUE NOT NULL
);
我得到的錯誤是
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '@AccountType varchar(50);
我似乎無法找出我是什麼做錯了。有人可以請幫助。
您的函數不是嚴格確定性的,因爲爲AccountTypeID返回的AccountType可以根據基礎表進行更改。 – pilcrow