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 ____________
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 ____________
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 ____________
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’.
4. The expression ‘2 BETWEEN 2 AND 5’ results in ____________
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.
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 _____________
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.
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.
8. The number of strings among the following matched with ‘%all%’ is _____________
Ball, baller, tall, tallest
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.
9. Which of the following is the correct order of precedence (high to low)?
a) !, ^, <<, XOR
b) ^, !, <<, XOR
c) !, <<, XOR, ^
d) !, ^, XOR, <<
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 _____________
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.