Challenge - 5 Problems
Type Casting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
Output of CAST with string to integer conversion
What is the output of the following MySQL query?
SELECT CAST('123abc' AS UNSIGNED) AS result;MySQL
SELECT CAST('123abc' AS UNSIGNED) AS result;
Attempts:
2 left
💡 Hint
MySQL converts strings to numbers by reading digits from the start until a non-digit is found.
✗ Incorrect
MySQL reads the string from left to right and converts the initial numeric part to an integer. Here, '123abc' converts to 123.
❓ query_result
intermediate1:30remaining
Result of CONVERT with incompatible type
What is the result of this MySQL query?
SELECT CONVERT('abc123', SIGNED) AS result;MySQL
SELECT CONVERT('abc123', SIGNED) AS result;
Attempts:
2 left
💡 Hint
When the string does not start with digits, MySQL returns zero for numeric conversion.
✗ Incorrect
Since 'abc123' starts with letters, MySQL cannot convert it to a number and returns 0.
📝 Syntax
advanced2:00remaining
Identify the correct syntax for casting to CHAR
Which of the following MySQL queries correctly casts the integer 100 to a CHAR type?
Attempts:
2 left
💡 Hint
CAST uses AS keyword, CONVERT uses comma to separate arguments.
✗ Incorrect
CAST syntax requires AS keyword. CONVERT uses comma without AS. Option A uses correct CAST syntax.
❓ query_result
advanced1:30remaining
Effect of implicit conversion in arithmetic operation
What is the output of this MySQL query?
SELECT '10' + 5 AS result;MySQL
SELECT '10' + 5 AS result;
Attempts:
2 left
💡 Hint
MySQL converts strings to numbers automatically in arithmetic expressions.
✗ Incorrect
The string '10' is implicitly converted to number 10, then added to 5, resulting in 15.
🧠 Conceptual
expert2:00remaining
Understanding behavior of CAST with floating point to integer
Consider the query:
What is the value of
SELECT CAST(123.987 AS SIGNED) AS result;What is the value of
result?MySQL
SELECT CAST(123.987 AS SIGNED) AS result;
Attempts:
2 left
💡 Hint
Casting from float to integer truncates the decimal part in MySQL.
✗ Incorrect
MySQL truncates the decimal part when casting float to integer, so 123.987 becomes 123.