Skip to content
Question

Q.Which MySQL string function is used to extract a substring from a given string based on a specified starting position and length ? (A) SUBSTRING_INDEX() (B) LENGTH() (C) MID() (D) TRIM()

CBSECBSE Class XII Board 2024MCQ· 1mImportance★★★★★
🔒 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 MID() function extracts a substring from a string by specifying a starting position and length.

When working with text data in MySQL, you often need to pull out just a portion of a string rather than the whole thing. Think of a database storing full names where you want only the first few characters, or product codes where specific segments carry meaning. MySQL provides several string functions for different slicing and extraction tasks, and understanding which does what is essential for efficient querying.

The function designed specifically to extract a substring based on both a starting position and a length is MID(). Its syntax is straightforward: MID(string, start, length). You tell it which string to work with, where to begin counting (the position), and how many characters to grab from that point forward. For example, MID('Database', 5, 4) would return 'base' — starting at the 5th character and taking 4 characters total.

Let's see why the other options don't fit:

  • SUBSTRING_INDEX() works differently — it splits a string based on a delimiter (like a comma or space) and returns everything before or after a specified occurrence of that delimiter. It doesn't use position and length; it uses pattern matching.

  • LENGTH() doesn't extract anything at all. It simply counts and returns the number of characters in a string, giving you a numeric value rather than a substring. …

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.