Recall & Review
beginner
What is a stored function in MySQL?
A stored function is a set of SQL statements stored in the database that performs a specific task and returns a single value.
Click to reveal answer
beginner
Which keyword is used to create a stored function in MySQL?
The CREATE FUNCTION keyword is used to define a stored function.
Click to reveal answer
beginner
What is the purpose of the
RETURNS clause in a stored function?The
RETURNS clause specifies the data type of the value that the function will return.Click to reveal answer
intermediate
Why do you need to use
DETERMINISTIC or NOT DETERMINISTIC when creating a stored function?It tells MySQL whether the function always returns the same result for the same input (
DETERMINISTIC) or not, which helps with optimization and caching.Click to reveal answer
beginner
How do you call a stored function in a SQL query?
You call it by using its name followed by parentheses with any required arguments, like a regular function:
SELECT function_name(args);Click to reveal answer
Which statement correctly creates a stored function that returns the square of a number?
✗ Incorrect
Option D uses CREATE FUNCTION with RETURNS INT and a BEGIN...END block returning x * x, which is correct syntax.
What does the RETURNS clause specify in a stored function?
✗ Incorrect
RETURNS specifies the data type of the value the function will return.
Which keyword indicates that a stored function always returns the same result for the same inputs?
✗ Incorrect
DETERMINISTIC means the function always returns the same result for the same inputs.
How do you execute a stored function named 'get_discount' with parameter 100?
✗ Incorrect
Stored functions are called using SELECT, e.g., SELECT get_discount(100);
Which of these is NOT allowed inside a stored function in MySQL?
✗ Incorrect
Stored functions cannot modify database tables; that is allowed in stored procedures only.
Explain the steps to create a stored function in MySQL that returns the length of a string.
Think about the function signature and the return statement.
You got /4 concepts.
Describe the difference between a stored function and a stored procedure in MySQL.
Focus on return values and how they are called.
You got /4 concepts.