Ispirer Ispirer
 


Ispirer Home Page Ispirer SQLWays Product Page - Migration to MySQL Request SQLWays

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


Ispirer Home Page Ispirer SQLWays Product Page - Migration to MySQL Request SQLWays

sqlways/mysql/string-functions.txt · Last modified: May 07, 2018, 03:15:28 PM (external edit)
 
© 1999-2018, Ispirer Systems Ltd.
All Rights Reserved.  Privacy Statement