Can a variable holds multiple records in user defined functions in MySQL?
I have a user defined function.
In that function I declared a variable of type datetime.
I am assigning the result of a query into this variable. And I am returning this assigned value. It looks like
delimiter$$
drop function if exists getQEDate$$
create function getQEDate() returns datetime
begin
declare qedate da开发者_开发技巧tetime;
select date into qedate from qenddates where ....;
return qedate;
end$$
delimiter ;
When accessing this function I am getting an exception like "returns more than a row...". So I am thinking this error occurred while returning the result. That means the variable qedate can hold more than one row.
Is the above analysis makes sense ?
It's probably that your query is returning more than 1 row and it can't store that into a variable. If you're only expecting 1 row you should check your where clause or add LIMIT 1 to the end of the query in the function.
I'm guessing since I can't see your data or your where clause :)
精彩评论