我正在将它从mssql转换为mysql,但它给了我这个错误:
错误代码:1415不允许从函数返回结果集
我做错了什么?
DELIMITER $$
CREATE FUNCTION GetPositionList (orderDetID NUMERIC)
RETURNS NVARCHAR(200)
DETERMINISTIC
BEGIN
DECLARE strToReturn NVARCHAR(50);
DECLARE strPos NVARCHAR(50);
DECLARE strPosOtherRes NVARCHAR(50);
DECLARE strTPos NVARCHAR(50);
DECLARE strTPosOtherResr NVARCHAR(50)
SET strToReturn = '';
SET strPos = SELECT `POSITION` FROM orderdetails WHERE OrderID = orderDetID;
SET strPosOtherRes = SELECT SecPosition FROM orderdetails WHERE OrderID = orderDetID;
SET strTPos = SELECT TeamPosition FROM orderdetails WHERE OrderID = orderDetID;
SET strTPosOtherResr = SELECT TeamSecPosition FROM orderdetails WHERE OrderID = orderDetID;
IF(strPos != '') THEN SET strToReturn = CONCAT(strPos , ',');
END IF;
IF(strPosOtherRes != '' ) THEN SET strToReturn = CONCAT(strToReturn , strPosOtherRes , ',');
END IF;
IF(strTPos != '' ) THEN SET strToReturn = CONCAT(strToReturn , strTPos , ',');
END IF;
IF(strTPosOtherResr != '' ) THEN SET strToReturn = CONCAT(strToReturn , strTPosOtherResr , ',');
END IF;
RETURN SUBSTRING( strToReturn, 0, LENGTH(strToReturn) );
END $$
DELIMITER ;
答案 0 :(得分:1)
在MySQL中选择值到变量的语法是select ... into
。例如,你可以写:
SELECT POSITION, SecPosition FROM orderdetails
WHERE OrderID = orderDetID INTO strPos, strPosOtherRes;
消息“不允许从函数返回结果集”意味着现在的select语句将从函数返回结果集,函数只能返回单个值。