0
0
MySQLquery~5 mins

Creating stored functions in MySQL - Quick Revision & Summary

Choose your learning style9 modes available
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?
ACREATE FUNCTION square(x INT) RETURNS VOID BEGIN RETURN x * x; END;
BCREATE PROCEDURE square(x INT) RETURNS INT BEGIN RETURN x * x; END;
CCREATE FUNCTION square(x INT) RETURNS INT RETURN x * x;
DCREATE FUNCTION square(x INT) RETURNS INT BEGIN RETURN x * x; END;
What does the RETURNS clause specify in a stored function?
AThe data type of the returned value
BThe name of the function
CThe input parameters
DThe SQL statements inside the function
Which keyword indicates that a stored function always returns the same result for the same inputs?
AIMMUTABLE
BNOT DETERMINISTIC
CDETERMINISTIC
DVOLATILE
How do you execute a stored function named 'get_discount' with parameter 100?
AEXEC get_discount(100);
BSELECT get_discount(100);
CCALL get_discount(100);
DRUN get_discount(100);
Which of these is NOT allowed inside a stored function in MySQL?
AModifying database tables with INSERT or UPDATE
BCalling another stored function
CDeclaring variables
DUsing control flow statements like IF
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.