Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start creating a stored function named 'getSquare'.
MySQL
CREATE FUNCTION getSquare(num INT) RETURNS INT [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using AS instead of BEGIN to start the function body.
Forgetting to start the function body with BEGIN.
✗ Incorrect
The BEGIN keyword starts the body of the stored function in MySQL.
2fill in blank
mediumComplete the code to return the square of the input number inside the function.
MySQL
RETURN [1] * num; END Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning num + 1 instead of num * num.
Using division or subtraction instead of multiplication.
✗ Incorrect
The function should return num * num to calculate the square.
3fill in blank
hardFix the error in the function declaration by completing the missing keyword.
MySQL
CREATE FUNCTION getDouble(num INT) RETURNS INT [1] RETURN num * 2; END
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using AS instead of BEGIN to start the function body.
Omitting the BEGIN keyword entirely.
✗ Incorrect
The function body must start with BEGIN before statements like RETURN.
4fill in blank
hardFill both blanks to declare a variable and set it to the square of the input number.
MySQL
DECLARE result INT; SET result = num [1] num; RETURN [2]; END
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of * for multiplication.
Returning num instead of the result variable.
✗ Incorrect
Use * to multiply and return the variable result.
5fill in blank
hardFill all three blanks to create a function that returns the cube of a number.
MySQL
CREATE FUNCTION getCube(num INT) RETURNS INT [1] DECLARE result INT; SET result = num [2] num [3] num; RETURN result; END
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using AS instead of BEGIN to start the function.
Using + or other operators instead of * for multiplication.
✗ Incorrect
Start the function body with BEGIN and multiply num three times using *.