A stored function is a special kind stored program that returns a single value.
You use stored functions to encapsulate common formulas or business rules that are reusable among SQL statements or stored programs.
Function Syntax:
CREATE FUNCTION function_name(param1,param2,…)
ANY STATEMENT
RETURNS datatype
END
Examples:
This function combined two Guids Return the result.
CREATE FUNCTION NEWCODE($LOCATIONCODE varchar(100))
RETURNS varchar(100) CHARSET utf8
BEGIN
SELECT UCASE(UUID()) INTO @id1;
SELECT UCASE(UUID()) INTO @ID2;
RETURN CONCAT(@ID1, '-', @ID2);
END
Result:
SELECT NEWCODE('');
0 Comments