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.
Different from stored procedure, you can use a stored function in sql statements whatever an expression is used. this helps improve the readability and maintainability of the procedural code.
Stored function syntax
CREATE FUNCTION function_name(param1,param2,....)
RETURNS datatype
[NOT] DETERMINISTIC
statement
Step-01
You must specify the data type of the return value in the RETURNS statement.
Step-02
You list all parameters of the stored function inside the parentheses by default, all parameters are the IN parameters. you can not specify IN,OUT or INOUT modifiers to the parameters.
Step-03
You specify the name of the stored function after CREATE FUNCTION clause.
Step-04
For the same input parameters, if the stored function returns the same result. it is considered deterministic; otherwise, the stored function after CREATE function clause.
No comments:
Post a Comment