0
0
MySQLquery~5 mins

FORMAT and LPAD/RPAD in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the FORMAT function do in MySQL?
The FORMAT function formats a number with a specified number of decimal places and adds commas as thousand separators. For example, FORMAT(12345.678, 2) returns '12,345.68'.
Click to reveal answer
beginner
How does LPAD work in MySQL?
LPAD adds characters to the left side of a string until it reaches a specified length. For example, LPAD('7', 3, '0') returns '007'.
Click to reveal answer
beginner
What is the difference between LPAD and RPAD?
LPAD pads characters on the left side of a string, while RPAD pads characters on the right side. Both make the string reach a specified length.
Click to reveal answer
beginner
Write a query to format the number 1234567.891 to 2 decimal places with commas.
SELECT FORMAT(1234567.891, 2); -- Result: '1,234,567.89'
Click to reveal answer
beginner
Write a query to pad the string 'abc' to length 6 by adding '*' on the right side.
SELECT RPAD('abc', 6, '*'); -- Result: 'abc***'
Click to reveal answer
What will FORMAT(98765.4321, 1) return?
A'98,765.4'
B'98765.4'
C'98,765.43'
D'98765.43'
What does LPAD('9', 4, '0') return?
A'009'
B'9000'
C'9'
D'0009'
Which function pads characters on the right side of a string?
ALPAD
BCONCAT
CRPAD
DFORMAT
What will RPAD('cat', 5, '!') return?
A'cat!!'
B'!!cat'
C'cat!'
D'cat'
If you want to format a number without any decimal places but with commas, which FORMAT call is correct?
AFORMAT(number, 1)
BFORMAT(number, 0)
CLPAD(number, 0, ',')
DRPAD(number, 0, ',')
Explain how FORMAT works in MySQL and give an example.
Think about how money amounts are shown with commas and decimals.
You got /4 concepts.
    Describe the difference between LPAD and RPAD with examples.
    Imagine adding zeros before or after a number to make it longer.
    You got /4 concepts.