0
0
MySQLquery~10 mins

FORMAT and LPAD/RPAD in MySQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to format the number 1234.567 to 2 decimal places.

MySQL
SELECT FORMAT(1234.567, [1]);
Drag options to blanks, or click blank then click option'
A2
B3
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 will remove decimals.
Using 3 will show too many decimals.
2fill in blank
medium

Complete the code to pad the string '42' on the left with zeros to make it 5 characters long.

MySQL
SELECT LPAD('42', [1], '0');
Drag options to blanks, or click blank then click option'
A3
B5
C4
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 will only add one zero.
Using 2 will not add any padding.
3fill in blank
hard

Fix the error in the code to pad the string 'abc' on the right with spaces to length 6.

MySQL
SELECT RPAD('abc', [1], ' ');
Drag options to blanks, or click blank then click option'
A3
B5
C6
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 will not add any padding.
Using 4 or 5 will add fewer spaces than needed.
4fill in blank
hard

Fill both blanks to format the number 9876.54321 with 3 decimals and pad the result on the left with '*' to length 12.

MySQL
SELECT LPAD(FORMAT(9876.54321, [1]), [2], '*');
Drag options to blanks, or click blank then click option'
A3
B10
C12
D8
Attempts:
3 left
💡 Hint
Common Mistakes
Using 10 for length will not pad enough.
Using 8 for length is too short for formatted string.
5fill in blank
hard

Fill all three blanks to pad the string 'data' on the right with '-' to length 10, then format the number 123.456 with 1 decimal place.

MySQL
SELECT FORMAT(123.456, [1]), RPAD('data', [2], [3]);
Drag options to blanks, or click blank then click option'
A1
B10
C'-'
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using 5 for length pads too little.
Using wrong padding character causes unexpected output.