What will be the output of following query?
SELECT INSTR("Computer Science", "ter");
What will be the output of following query?
SELECT INSTR("Computer Science", "ter");
Solution
✅ Correct Option: 2
INSTR(str, substr) returns the 1-based position where substr first appears in str. Counting the letters of "Computer Science" gives C = 1, o = 2, m = 3, p = 4, u = 5, t = 6, e = 7, r = 8. So "ter" starts at position 6.
Option 1: 5 would be the position if counting started from 0, as in Python. SQL positions start from 1.
Options 3 and 4: INSTR returns 0 when the substring is not found, and -1 is what Python's find() returns. Here "ter" is present, so neither applies.
Related questions:
2025: 15 May Shift 2
2026: 13 May Shift 2