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

MySQLMySQLi Database

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.

raja
Published on 20-Feb-2018 17:38:57
Advertisements