Exit Chapter 06 ยท ๐Ÿ“š MySQL Functions โ€” Quiz

Playing as a guest? to earn XP and track your progress.

Question 1 of 50 0 correct so far

๐Ÿ“š MySQL Functions Quiz

Q1.

What is the return value of SELECT ROUND(15.193, 1)?

Explanation

ROUND(15.193, 1) rounds to 1 decimal place. Since the second decimal (9) is >= 5, the first decimal (1) increments to 2.

Q2.

Which function returns the position of the first occurrence of a substring?

Explanation

INSTR(string, substring) returns the index of the first occurrence. Returns 0 if not found.

Q3.

What is the output of SELECT SUBSTR('Computer', 4, 3)?

Explanation

Starts at position 4 ('p') and extracts 3 characters ('p', 'u', 't').

Q4.

Which function returns the remainder of a division?

Explanation

MOD(N, M) or N % M returns the remainder.

Q5.

Identify the output of SELECT TRUNCATE(123.456, 1).

Explanation

TRUNCATE removes digits after the specified position without rounding.

Q6.

What does SELECT DAYOFWEEK('2023-12-03') return if the date is a Sunday?

Explanation

By default in MySQL, 1 = Sunday, 2 = Monday, ..., 7 = Saturday.

Q7.

Output of SELECT CONCAT('Hi', NULL, 'There')?

Explanation

If any argument in CONCAT is NULL, the result is NULL.

Q8.

Which function removes both leading and trailing spaces?

Explanation

TRIM() removes whitespace from both ends of the string.

Q9.

Result of SELECT ROUND(256.78, -2)?

Explanation

Rounding with -2 operates on the hundreds place. 256 is closer to 300.

Q10.

Which function works similarly to SUBSTR?

Explanation

MID(), SUBSTR(), and SUBSTRING() are synonyms in MySQL.

Q11.

What will SELECT SIGN(-15) return?

Explanation

SIGN returns -1 for negative numbers, 1 for positive, and 0 for zero.

Q12.

Output of SELECT POWER(2, 3)?

Explanation

Calculates 2 raised to the power of 3 (222 = 8).

Q13.

What does SELECT NOW() return?

Explanation

NOW() returns the current date and time.

Q14.

Output of SELECT LENGTH('Data')?

Explanation

Returns the length of the string in bytes (4 characters = 4 bytes for standard ASCII).

Q15.

What is the output of SELECT LCASE('MySql')?

Explanation

LCASE (or LOWER) converts all characters to lowercase.

Q16.

Output of SELECT LEFT('Informatics', 2)?

Explanation

Extracts the first 2 characters from the left.

Q17.

What does SELECT YEAR('2023-05-10') return?

Explanation

Extracts the year part from the date.

Q18.

Result of SELECT ROUND(1.5)?

Explanation

When no decimal count is provided, ROUND rounds to the nearest integer. 1.5 rounds up to 2.

Q19.

Output of SELECT MOD(10, 3)?

Explanation

10 divided by 3 is 3 with a remainder of 1.

Q20.

What does SELECT SQRT(25) return?

Explanation

Returns the square root of 25.

Q21.

Output of SELECT RIGHT('Science', 3)?

Explanation

Extracts the last 3 characters from the right ('n', 'c', 'e').

Q22.

Which function is used to return the current date only?

Explanation

CURDATE() returns the date portion (YYYY-MM-DD).

Q23.

Output of SELECT INSTR('Hello', 'z')?

Explanation

Returns 0 because 'z' is not found in 'Hello'.

Q24.

What is SELECT DAYNAME('2023-01-01')'s return type?

Explanation

DAYNAME returns the name of the day (e.g., 'Sunday') which is a string.

Q25.

Output of SELECT TRUNCATE(15.79, 0)?

Explanation

Truncates to 0 decimal places (removes decimals), so 15.79 becomes 15.

Q26.

Which function converts ASCII value to Character?

Explanation

CHAR() converts integer ASCII codes into their corresponding characters.

Q27.

Result of SELECT ROUND(125.55, -1)?

Explanation

Rounds to the nearest ten. 125.55 rounds up to 130.

Q28.

What does SELECT MONTHNAME('2023-03-15') return?

Explanation

Returns the full name of the month.

Q29.

Output of SELECT SUBSTR('ABCDEFG', -3)?

Explanation

Negative index counts from the right. Starts at 3rd from last ('E') and takes the rest.

Q30.

Result of SELECT LTRIM(' Text')?

Explanation

Removes leading spaces from the left.

Q31.

Which represents 'Square Root' in SQL?

Explanation

SQRT is the dedicated function, though POWER(x, 0.5) also works mathematically, SQRT is the standard function name requested.

Q32.

Output of SELECT LENGTH(TRIM(' A '))?

Explanation

TRIM removes 2 leading and 2 trailing spaces, leaving 'A' (length 1).

Q33.

What does SELECT DAYOFMONTH('2023-02-14') return?

Explanation

Returns the day number of the month (14).

Q34.

Output of SELECT CHAR(65)?

Explanation

ASCII 65 corresponds to 'A'.

Q35.

Result of SELECT SIGN(0)?

Explanation

SIGN of zero is 0.

Q36.

Output of SELECT TRUNCATE(1234.56, -2)?

Explanation

Truncates at the hundreds place (-2). Digits 3 and 4 become 0. No rounding.

Q37.

Output of SELECT CONCAT('Key', 'Board')?

Explanation

Joins strings without any separator.

Q38.

Function to get the day of the year (1-366)?

Explanation

DAYOFYEAR returns the running day count of the year.

Q39.

Output of SELECT ROUND(3.14159, 3)?

Explanation

Rounds to 3 decimals. Next digit is 5, so 3.141 becomes 3.142.

Q40.

Which function converts 'abc' to 'ABC'?

Explanation

UPPER() (or UCASE) converts to uppercase.

Q41.

Output of SELECT MID('CloudComputing', 6, 4)?

Explanation

Starts at 6th char ('C' of Computing) and takes 4 chars: 'Comp'.

Q42.

Result of SELECT MOD(20, 6)?

Explanation

20 divided by 6 is 3 with a remainder of 2.

Q43.

Output of SELECT SUBSTR('Hello World', 7)?

Explanation

If length is omitted, it takes everything from the start position (7) to the end.

Q44.

Output of SELECT LENGTH(12345)?

Explanation

MySQL implicitly converts numbers to strings for LENGTH. '12345' has 5 chars.

Q45.

Result of SELECT ROUND(-1.23)?

Explanation

-1.23 is closer to -1 than -2.

Q46.

Which statement is true about SYSDATE() vs NOW()?

Explanation

NOW() returns the constant time at which the statement began execution; SYSDATE() returns the exact time the function executes (important in long queries).

Q47.

Output of SELECT INSTR('banana', 'a')?

Explanation

Finds the first occurrence of 'a', which is at index 2.

Q48.

Output of SELECT POWER(4, 0.5)?

Explanation

Power of 0.5 is equivalent to Square Root. Sqrt(4) = 2.

Q49.

What is the index of the first character in a MySQL string?

Explanation

SQL strings are 1-indexed.

Q50.

Result of SELECT RIGHT('2023', 2)?

Explanation

Takes the last 2 characters '23'.