Skip to content
Question

Q.What will be the output of the following query ? SELECT SUBSTR(“G20 2023 INDIA”,5,4); (A) G20 2 (B) 2023 (C) INDI (D) 023

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 query extracts a substring of length 4 starting from the 5th character of the given string, so the output is "2023".

The SUBSTR function in SQL is used to extract a portion of a string. It takes three arguments: the original string, the starting position, and the length of the substring to be extracted. The starting position is counted from the left, beginning with 1 for the first character.

In the query SELECT SUBSTR("G20 2023 INDIA",5,4);, the string is "G20 2023 INDIA". Let's count the characters carefully:

  • Position 1: G
  • Position 2: 2
  • Position 3: 0
  • Position 4: (space)
  • Position 5: 2
  • Position 6: 0
  • Position 7: 2
  • Position 8: 3

So starting from position 5, the characters are "2", "0", "2", "3". The length specified is 4, so we take exactly these four characters, giving us "2023".

Note

In SQL, string positions typically start at 1, not 0. This is different from some programming languages like Python or C where indexing starts at 0.

Watch out

A common mistake is to miscount the space at position 4. The space is a valid character and must be counted. If you forget the space, you might think position 5 is "0" instead of "2", leading to the wrong answer.

Now let's look at the 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.