Skip to content
Question 31 of 40

Q.If the substring is not present in a string, the INSTR ( ) returns: (A) - 1 (B) 1 (C) NULL (D) 0

Puducherry TnboardCBSE Class XII Board 2023MCQ· 1mImportance★★★★★
78% · 31/40 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

The INSTR() function in SQL returns the starting position of a substring within a string. If the substring is not found, it returns 0, not NULL or -1. The correct answer is (D) 0.

The Concept: Why INSTR() Returns 0

The INSTR() function is a standard string function in SQL (used in Oracle, MySQL, and others) that searches for a substring inside a larger string. It returns the character position where the substring first appears, counting from 1. This is a positional index, not a boolean flag.

The key intuition: in SQL, positions are 1-based. If the substring is the very first character, the result is 1. If it's the second character, the result is 2, and so on. But what happens when the substring simply isn't there? The function cannot return a valid position — so it returns 0, meaning "no match found." This is consistent with how many other SQL string functions (like LOCATE() or POSITION()) behave.

Watch out

A common mistake is to think INSTR() returns -1 or NULL when no match is found, as some other programming languages do (e.g., Python's str.find() returns -1). But SQL's INSTR() returns 0 — a clean, non-negative integer that fits naturally with 1-based indexing.

Step-by-Step Reasoning

  1. Understand the function signature.

    INSTR(string, substring) returns the starting position of the first occurrence of substring within string. For example:

    INSTR('Hello World', 'World') returns 7 (since 'W' is the 7th character).

    INSTR('Hello World', 'o') returns 5 (the first 'o' is at position 5).

  2. Consider the case of no match.

    If the substring does not appear anywhere in the string, there is no valid starting position. The function cannot return a position number (1, 2, 3, …), so it returns 0. This is the standard SQL convention.

  3. Eliminate the other options. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.