Challenge - 5 Problems
Master of LENGTH and CHAR_LENGTH
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Difference between LENGTH and CHAR_LENGTH with multibyte characters
Consider the string 'café' stored in a UTF-8 encoded MySQL database. What is the output of the following query?
SELECT LENGTH('café') AS length_bytes, CHAR_LENGTH('café') AS length_chars;MySQL
SELECT LENGTH('café') AS length_bytes, CHAR_LENGTH('café') AS length_chars;
Attempts:
2 left
💡 Hint
Remember that LENGTH counts bytes, and CHAR_LENGTH counts characters.
✗ Incorrect
The character 'é' in UTF-8 uses 2 bytes. So 'café' has 4 characters but 5 bytes total.
❓ query_result
intermediate1:30remaining
Using LENGTH and CHAR_LENGTH on ASCII string
What is the output of this query?
SELECT LENGTH('hello') AS length_bytes, CHAR_LENGTH('hello') AS length_chars;MySQL
SELECT LENGTH('hello') AS length_bytes, CHAR_LENGTH('hello') AS length_chars;
Attempts:
2 left
💡 Hint
ASCII characters use 1 byte each.
✗ Incorrect
Each ASCII character is 1 byte, so both LENGTH and CHAR_LENGTH return 5.
📝 Syntax
advanced1:30remaining
Identify the syntax error in LENGTH usage
Which option contains a syntax error when using LENGTH or CHAR_LENGTH functions in MySQL?
Attempts:
2 left
💡 Hint
Check the parentheses usage in function calls.
✗ Incorrect
MySQL requires parentheses around function arguments. Option A misses parentheses causing syntax error.
🧠 Conceptual
advanced2:00remaining
Why use CHAR_LENGTH instead of LENGTH for user input?
Why is it better to use CHAR_LENGTH instead of LENGTH when validating the length of user input strings in a UTF-8 encoded MySQL database?
Attempts:
2 left
💡 Hint
Think about multibyte characters and user experience.
✗ Incorrect
CHAR_LENGTH counts characters, so it matches what users expect when counting input length, especially with multibyte characters.
❓ query_result
expert2:30remaining
Output of LENGTH and CHAR_LENGTH on emoji string
What is the output of this query?
Assume the database uses UTF-8 encoding.
SELECT LENGTH('👍👍') AS length_bytes, CHAR_LENGTH('👍👍') AS length_chars;Assume the database uses UTF-8 encoding.
MySQL
SELECT LENGTH('👍👍') AS length_bytes, CHAR_LENGTH('👍👍') AS length_chars;
Attempts:
2 left
💡 Hint
Emoji characters usually use 4 bytes each in UTF-8.
✗ Incorrect
Each '👍' emoji is 4 bytes in UTF-8, so LENGTH returns 8 bytes total, CHAR_LENGTH counts 2 characters.