Challenge - 5 Problems
FORMAT and LPAD/RPAD Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of FORMAT with decimal places?
Consider the following MySQL query:
What is the output of this query?
SELECT FORMAT(12345.6789, 2);
What is the output of this query?
MySQL
SELECT FORMAT(12345.6789, 2);
Attempts:
2 left
💡 Hint
FORMAT rounds the number and adds commas as thousand separators.
✗ Incorrect
FORMAT rounds the number to the specified decimal places and adds commas as thousand separators. So 12345.6789 rounded to 2 decimals is 12345.68, displayed with a comma as '12,345.68'.
❓ query_result
intermediate2:00remaining
What does LPAD do with a string?
Given this query:
What is the output?
SELECT LPAD('42', 5, '0');What is the output?
MySQL
SELECT LPAD('42', 5, '0');
Attempts:
2 left
💡 Hint
LPAD adds characters to the left until the string reaches the specified length.
✗ Incorrect
LPAD pads the string '42' on the left with '0' characters until the total length is 5. So it adds three zeros to the left, resulting in '00042'.
❓ query_result
advanced2:00remaining
What is the result of RPAD with a multi-character pad string?
Analyze this query:
What is the output?
SELECT RPAD('abc', 7, 'xy');What is the output?
MySQL
SELECT RPAD('abc', 7, 'xy');
Attempts:
2 left
💡 Hint
RPAD repeats the pad string as many times as needed to reach the length.
✗ Incorrect
RPAD pads 'abc' on the right with 'xy' repeated until length 7 is reached. 'abc' is length 3, so 4 more characters are needed. 'xyxy' is 4 characters, so result is 'abcxyxy'.
📝 Syntax
advanced2:00remaining
Which query will cause a syntax error?
Identify which of these MySQL queries will cause a syntax error:
Attempts:
2 left
💡 Hint
Check the syntax of the FORMAT function parameters.
✗ Incorrect
Option B is missing a comma between the number and the decimal places, causing a syntax error. The others have correct syntax.
🧠 Conceptual
expert2:00remaining
How does FORMAT handle locale in MySQL?
Which statement about the FORMAT function's locale behavior in MySQL is true?
Attempts:
2 left
💡 Hint
Check the MySQL documentation for FORMAT function parameters.
✗ Incorrect
In MySQL, FORMAT(number, decimal_places, locale) allows specifying a locale string as the third argument to control decimal and thousand separators.