[英]MySQL - Function keeps returning null
我正在嘗試創建一個MySQL函數,該函數將存儲員工在項目上的時間並將其存儲在v_emptime
,然后使用該變量來計算總費用,如下所示:
delimiter //
create function F_COUNT_EDUCATION (p_empno char(6)) returns decimal(10, 2)
begin
declare v_emptime decimal(5, 2);
declare output decimal(10, 2);
select sum(emptime) # There are multiple records for some, using sum() for total time
into @v_emptime
from empprojact
where empno = p_empno;
# if I return v_emptime here it will be null
select (@v_emptime * comm + salary + bonus) expense
into @output
from employee
where empno = p_empno;
return @output;
end //
delimiter ;
但是,問題在於output
將始終返回null。 我檢查了無數次數據,並且所有數據都有值。 這意味着我可能忽略了一些非常簡單的內容。 任何幫助或見解將不勝感激,謝謝!
嘗試以下操作:更改“ @output”變量的名稱。 並更改查詢此:
select @v_emptime = sum(emptime)
from empprojact
where empno = p_empno;
和:
select @newVariableName = (@v_emptime * comm + salary + bonus) expense
from employee where empno = p_empno;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.