While Stored Procedures are designed to perform procedural tasks and return full result sets, Stored Functions (User-Defined Functions) are designed to compute and return a single scalar value.
Because functions return a scalar value, they can be invoked directly inside standard SQL expressions: in SELECT lists, WHERE filters, ORDER BY clauses, and HAVING checks.
If binary logging is enabled on your MySQL server, creating functions requires declaring their deterministic nature. If you encounter: ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled
You can resolve this either by declaring DETERMINISTIC or toggling:
1SETGLOBAL log_bin_trust_function_creators =1;
Interactive Quiz• Knowledge Check
Multiple Choice Questions
Question 1
How does a Stored Function fundamentally differ from a Stored Procedure in MySQL?
Question 2
Which keyword specifies the return data type in a stored function signature?
Question 3
Which statement is used inside the function body to output the calculated result?
Question 4
How is a stored function called in SQL?
Question 5
Why does MySQL require function authors to specify DETERMINISTIC or READS SQL DATA when binary logging is active?
Next Lesson
Deterministic vs Non-Deterministic Functions
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.