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


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.

Updated on: 22-Jun-2020

117 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements