0
0
MySQLquery~20 mins

FORMAT and LPAD/RPAD in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
FORMAT and LPAD/RPAD Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of FORMAT with decimal places?
Consider the following MySQL query:
SELECT FORMAT(12345.6789, 2);

What is the output of this query?
MySQL
SELECT FORMAT(12345.6789, 2);
A'12,345.68'
B'12345.67'
C'12,345.6789'
D'12345.68'
Attempts:
2 left
💡 Hint
FORMAT rounds the number and adds commas as thousand separators.
query_result
intermediate
2:00remaining
What does LPAD do with a string?
Given this query:
SELECT LPAD('42', 5, '0');

What is the output?
MySQL
SELECT LPAD('42', 5, '0');
A'42'
B'42000'
C'00042'
D'000042'
Attempts:
2 left
💡 Hint
LPAD adds characters to the left until the string reaches the specified length.
query_result
advanced
2:00remaining
What is the result of RPAD with a multi-character pad string?
Analyze this query:
SELECT RPAD('abc', 7, 'xy');

What is the output?
MySQL
SELECT RPAD('abc', 7, 'xy');
A'abcxyx'
B'abcxyxyz'
C'abcxy'
D'abcxyxy'
Attempts:
2 left
💡 Hint
RPAD repeats the pad string as many times as needed to reach the length.
📝 Syntax
advanced
2:00remaining
Which query will cause a syntax error?
Identify which of these MySQL queries will cause a syntax error:
ASELECT FORMAT(9876.543, 1);
BSELECT FORMAT(1234.56 2);
CSELECT RPAD('test', 6, '-');
DSELECT LPAD('test', 6, '*');
Attempts:
2 left
💡 Hint
Check the syntax of the FORMAT function parameters.
🧠 Conceptual
expert
2:00remaining
How does FORMAT handle locale in MySQL?
Which statement about the FORMAT function's locale behavior in MySQL is true?
AFORMAT can take an optional third argument to specify locale for formatting.
BFORMAT always uses the server's default locale for decimal and thousand separators.
CFORMAT ignores locale and always uses '.' for decimal and ',' for thousands.
DFORMAT uses the client's locale settings automatically without extra parameters.
Attempts:
2 left
💡 Hint
Check the MySQL documentation for FORMAT function parameters.