# What happens if the argument ‘count’ in MySQL SUBSTRING_INDEX() function has the value greater than the total number of occurrences of delimiter?

MySQLMySQLi Database

MySQL SUBSTRING_INDEX() function will return the same string as output if the argument ‘count’ has the value greater than the total number of occurrences of delimiter. It can be demonstrated with the following example −

mysql> Select SUBSTRING_INDEX('My Name is Ram','a',3);
+-----------------------------------------+
| SUBSTRING_INDEX('My Name is Ram','a',3) |
+-----------------------------------------+
| My Name is Ram                          |
+-----------------------------------------+
1 row in set (0.00 sec)

The above query returns the same string because 3 is greater than the total number of occurrences of delimiter provided as argument i.e. ‘a’. There are only two ‘a’ in the string.

Published on 21-Feb-2018 08:10:16