create function sk( age int) returns varchar(30) deterministic
begin
declare value varchar(30);
select sname into value from student where student.age=age;
return value;
end;
//
select sk(19);
错误1172(42000):结果包含多于一行
答案 0 :(得分:0)
您无需在LIMIT 1
语句中设置SELECT
,这样您将拥有标量而不是数据集。
DELIMITER //
CREATE FUNCTION sk(age INT)
RETURNS VARCHAR(30) DETERMINISTIC
BEGIN
DECLARE value VARCHAR(30);
SELECT sname INTO value
FROM student
WHERE student.age = age
LIMIT 1;
RETURN value;
END//
DELIMITER ;