Skip to main contentSkip to solution

Which of the following are valid functions to returns a substring of size 'n' starting from the specified position (pos) of the string?

A. INSTR(string, pos)

B. MID(string, pos, n)

C. SUBSTRING(string, pos, n)

D. SUBSTR(string, pos, n)

Solution

✅ Correct Option: 4

MID(), SUBSTRING() and SUBSTR() in MySQL all return nn characters of a string starting at position pos, so B, C and D are valid.

For example, MID(’Informatics’, 3, 4)\text{MID('Informatics', 3, 4)}, SUBSTRING(’Informatics’, 3, 4)\text{SUBSTRING('Informatics', 3, 4)} and SUBSTR(’Informatics’, 3, 4)\text{SUBSTR('Informatics', 3, 4)} each return "form".


A: INSTR(string, substring) returns the position of the first occurrence of a substring inside a string. It does not extract text, and its second argument is a substring to search for, not a position.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question