How can MySQL SUBSTRING() function be used with FROM and FOR keywords?


The syntax of SUBSTRING() function using FROM and FOR keywords is the standard MySQL syntax.

Syntax

SUBSTRING(str FROM pos FOR len)

Here, 

  • str is the string from which substring would be returned.
  • Pos is the starting position of substring.
  • Len is the length of substring i.e. the total number of characters fetched from str.

Example

mysql> Select SUBSTRING('foobarbar' FROM 4 FOR 5);
+-------------------------------------+
| SUBSTRING('foobarbar' FROM 4 FOR 5) |
+-------------------------------------+
| barba                               |
+-------------------------------------+
1 row in set (0.00 sec)

The result set above, makes the use of FROM and FOR keywords very much clear in SUBSTRING() function.

Updated on: 10-Feb-2020

130 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements