I've tried reading numerous help pages about functions in MySQL but am failing to grasp a core concept. In the example below: What is the point of starting_value
and why can't it just be CREATE FUNCTION
CalcIncome (Int) ?
DELIMITER //
CREATE FUNCTION CalcIncome ( starting_value INT )
RETURNS INT
BEGIN
DECLARE income INT;
SET income = 0;
label1: WHILE income <= 3000 DO
SET income = income + starting_value;
END WHILE label1;
RETURN income;
END; //
DELIMITER ;
starting_value is the identifier by which to use the value passed in. It doesn't always make sense to have the function name the same as the parameter name. The way that I think of it is if you have a function f(x) where x is an int, .... wouldn't it look a bit confusing sometimes if it were something like f(F) or something like that? :)
in the case above the f(F) would be what the calc_income(Calc_Income) would be kind of like
I hope that helps