State the output of the following query.
SELECT LENGTH(MID('INFORMATICS PRACTICES',5,-5));
State the output of the following query.
SELECT LENGTH(MID('INFORMATICS PRACTICES',5,-5));
Solution
✅ Correct Option: 1,3
MID(str, pos, len) works like SUBSTRING. When len is zero or negative, it returns an empty string, so gives an empty string and no characters are extracted.
LENGTH of an empty string is 0, so the query returns 0. The substring itself is empty, which is why NO OUTPUT is also accepted along with 0.
Option 2: 5 comes from ignoring the minus sign. A negative length does not count backwards.
Option 4: MySQL does not raise an error for a negative length in MID.
Related questions:
2026: 18 May Shift 2
2026: 29 May Shift 2