-3

我正在将它从 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 ; 
4

1 回答 1

1

在 MySQL 中为变量选择值的语法是select ... into. 例如你可以写:

SELECT POSITION, SecPosition FROM orderdetails 
WHERE OrderID = orderDetID INTO strPos, strPosOtherRes;

消息“不允许从函数返回结果集”意味着现在的选择语句将从函数返回结果集,并且函数只能返回单个值。

于 2012-08-03T09:03:09.080 回答