0
0
MySQLquery~20 mins

Type casting and conversion in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Type Casting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
1: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;
A123abc
B0
CSyntax error
D123
Attempts:
2 left
💡 Hint
MySQL converts strings to numbers by reading digits from the start until a non-digit is found.
query_result
intermediate
1: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;
Aabc123
B123
C0
DNULL
Attempts:
2 left
💡 Hint
When the string does not start with digits, MySQL returns zero for numeric conversion.
📝 Syntax
advanced
2:00remaining
Identify the correct syntax for casting to CHAR
Which of the following MySQL queries correctly casts the integer 100 to a CHAR type?
ASELECT CAST(100 AS CHAR);
BSELECT CAST(100 TO CHAR);
CSELECT CONVERT(100, CHAR);
DSELECT CONVERT(100 AS CHAR);
Attempts:
2 left
💡 Hint
CAST uses AS keyword, CONVERT uses comma to separate arguments.
query_result
advanced
1: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;
A15
B'105'
C10 5
DError
Attempts:
2 left
💡 Hint
MySQL converts strings to numbers automatically in arithmetic expressions.
🧠 Conceptual
expert
2:00remaining
Understanding behavior of CAST with floating point to integer
Consider the query:

SELECT CAST(123.987 AS SIGNED) AS result;

What is the value of result?
MySQL
SELECT CAST(123.987 AS SIGNED) AS result;
A124
B123
C123.987
DError
Attempts:
2 left
💡 Hint
Casting from float to integer truncates the decimal part in MySQL.