gpt4 book ai didi

mysql - 错误代码 : 1241 Operand should contain 1 column(s)

转载 作者:行者123 更新时间:2023-11-29 00:47:40 24 4
gpt4 key购买 nike

在 mysql 中创建一个函数,当函数被调用时我得到“错误代码:1241 Operand should contain 1 column(s)"如何解决错误

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;

我收到“错误代码:1241”

Operand should contain 1 column(s)"如何解决错误

最佳答案

您在 SET 子查询中选择了多个列,而 age 期望是单个 INT 值。你不想要这里的 *:

set age=(SELECT YEAR(CURDATE()) - YEAR(Dob)   FROM per_det where username=Username);

关于mysql - 错误代码 : 1241 Operand should contain 1 column(s),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9927232/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com