create a function in mysql,when a function is call i got "Error Code: 1241 Operand should contain 1 column(s)" how to solve the error
drop function if exists age;
DELIMITER //
CREATE FUNCTION age (Dob date,Username varchar(30))
RETURNS INT
DETERMINISTIC
BEGIN
DECLARE age int;
set age=(SELECT *, YEAR(CURDATE()) - YEAR(Dob) FROM per_det where username=Username);
return age;
END;//
delimiter ;
select * from per_det;
i got "Error Code: 1241
Operand should contain 1 column(s)" how to solve the error
You're selecting multiple columns in the
SET
subquery, whileage
expects to be a singleINT
value. You don't want the*
here: