MySQL Questions and Answers – Expression Evaluation and Type Conversion

This set of MySQL Database Multiple Choice Questions & Answers (MCQs) focuses on “Expression Evaluation and Type Conversion”.

1. The expression 12 DIV 5 evaluates to ____________
a) 2.4
b) 2
c) error
d) 0
View Answer

Answer: b
Explanation: The ‘DIV’ operator in MySQL is used to perform the integer divisions. The operator ‘/’ performs the quotient of the operands. If result exceeds the 64-bit range, unpredicted results are shown.

2. If the PIPES_AS_CONCAT is disabled, ‘abc’ || ‘xyz’ results in ____________
a) 1
b) 0
c) error
d) -1
View Answer

Answer: b
Explanation: When the SQL mode PIPES_AS_CONCAT is disabled, the SQL standard ‘||’ operation for string concatenation is not valid in MySQL. Both operands are converted to zero. So the result is zero.

3. ‘abc’ || ‘xyz’, when PIPES_AS_CONCAT is enabled, results in ____________
a) 0
b) 1
c) abcxyz
d) xyzabc
View Answer

Answer: c
Explanation: If the SQL mode PIPES_AS_CONCAT has been enabled, the SQL standard ‘||’ operation for string concatenation becomes valid in MySQL. Both operands are concatenated to give ‘abcxyz’.
advertisement
advertisement

4. The expression ‘2 BETWEEN 2 AND 5’ results in ____________
a) True
b) False
c) -1
d) 2
View Answer

Answer: a
Explanation: The ‘BETWEEN ……. AND’ clause is used to return a boolean value, if the given operand value lies between the values specified by the ‘AND’ clause. The range endpoints are inclusive.

5. REGEXP takes collation into account.
a) True
b) False
View Answer

Answer: b
Explanation: MySQL provides pattern matching based on the ‘REGEXP’ operator and regular expressions that are similar to those used in Unix programs, namely, grep, sed and vi. REGEXP does not take collation into account.

6. The expression ‘HI’ LIKE NULL results in _____________
a) True
b) False
c) NULL
d) 0
View Answer

Answer: c
Explanation: In MySQL, any pattern matching that is performed with the ‘NULL’ operand, fails. Expressions like: ‘abcdef’ LIKE NULL, NULL LIKE ‘%’, all result into the value NULL. NULL is not used to perform comparisons.

7. If the operands are non binary strings, LIKE compares them according to their collation.
a) True
b) False
View Answer

Answer: a
Explanation: In MySQL, the LIKE operator compares its operands as binary strings if either operand is a binary string. If the operands are non binary strings, the LIKE operator compares them according to their collation.
advertisement

8. The number of strings among the following matched with ‘%all%’ is _____________

Ball, baller, tall, tallest

a) 1
b) 2
c) 3
d) 4
View Answer

Answer: d
Explanation: In MySQL, the wildcard characters may be specified anywhere in a pattern. The ‘%’ wildcard is used to match variable number of characters. Here, the wildcard matches all the four words.
advertisement

9. Which of the following is the correct order of precedence (high to low)?
a) !, ^, <<, XOR
b) ^, !, <<, XOR
c) !, <<, XOR, ^
d) !, ^, XOR, <<
View Answer

Answer: a
Explanation: When MySQL evaluates an expression, it looks at the operators to determine the order in which it should group the terms of the expression. Some operators have higher precedence, and evaluated earlier than others.

10. 0x61 + 0 results in _____________
a) 0
b) ‘a’
c) 97
d) arbitrary
View Answer

Answer: c
Explanation: The hexadecimal constants are treated as binary strings unless the context indicates a number. In the string contexts, each pair of hexadecimal digits is converted to a character, then the result is used as a string.

Sanfoundry Global Education & Learning Series – MySQL Database.

To practice all areas of MySQL Database, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.