Table of Contents
Ispirer Website
Ispirer Capabilities - MySQL Migration
Free Trial
MySQL - String Functions
This article describes string functions in MySQL.
Overview
String Function | Description |
---|---|
LOCATE() | Position of substring in string |
LOCATE
MySQL - LOCATE | |
---|---|
Syntax | LOCATE(substring, string [, start_position]) |
Description | LOCATE searches string for substring. start_position indicates the position to begin the search |
Return Value | LOCATE returns the position of the first character or 0 if the substring is not found. The return type is INTEGER |
Default Values | start_position is 1 |
Examples:
- Return the first occurrence of 'CD'
mysql> SELECT LOCATE('CD', 'ABCDCD'); +------------------------+ | 3 | +------------------------+ 1 row in set (0.00 sec)
- Return the second occurrence of 'CD' using a nested LOCATE
mysql> SELECT LOCATE('CD', 'ABCDCD', LOCATE('CD', 'ABCDCD')+1); +------------------------+ | 5 | +------------------------+ 1 row in set (0.01 sec)
MySQL LOCATE - Equivalents in Other Databases
Database | Equivalent |
---|---|
Oracle | INSTR(string, substring, start_position, occurrence) - Different parameter order, option to specify occurrence number |