我想创建一个具有以下查询的函数,但会发生错误
DELIMITER $$
CREATE FUNCTION getOnlineUserTraffic (x1 VARCHAR(32))
RETURNS FLOAT
DETERMINISTIC
BEGIN
DECLARE dist FLOAT;
SET dist = SELECT UsedCreditTraffic FROM uonlineuser WHERE UserName=x1
RETURN dist;
END$$
DELIMITER ;
// userName = char,长度= 32
// UsedCreditTraffic = float
答案 0 :(得分:1)
尝试:
DELIMITER $$
DROP FUNCTION IF EXISTS getOnlineUserTraffic$$
CREATE FUNCTION getOnlineUserTraffic(x1 VARCHAR(32))
RETURNS FLOAT
DETERMINISTIC
BEGIN
DECLARE dist FLOAT;
SET dist = (SELECT UsedCreditTraffic FROM uonlineuser WHERE UserName=x1);
RETURN dist;
END$$
DELIMITER ;