Collections:
LOCATE() - Locate Substring Starting at N
How to locate a substring using the LOCATE() function?
✍: FYIcenter.com
LOCATE(substr, str, pos)
is a MySQL built-in function that
searches a substring in a string starting at a given position
and returns the location of the substring.
For example:
SET @str = 'Row, row, row your boat';
SELECT LOCATE('row', @str, 7);
-- +------------------------+
-- | LOCATE('row', @str, 7) |
-- +------------------------+
-- | 11 |
-- +------------------------+
Reference information of the LOCATE() function:
LOCATE(substr, str, pos): location Returns the position of the first occurrence of substring substr in string str, starting at position pos. Returns 0 if substr is not in str. Returns NULL if any argument is NULL. Arguments, return value and availability: substr: Required. The substring to search for. str: Required. The string that will be searched in. pos: Optional. Default is 1. The position to start the search. location: Return value. The position where is substring is located. Available since MySQL 4.0.
Related MySQL functions:
⇒ LOWER() - Convert String to Lower Case
⇐ LENGTH() - Number of Bytes in String
2023-11-12, 1014🔥, 0💬
Popular Posts:
How To Generate CREATE VIEW Script on an Existing View in SQL Server? If you want to know how an exi...
How To Install Oracle Database 10g XE in Oracle? To install 10g universal edition, double click, Ora...
What is sqlservr.exe - Process - SQL Server (SQLEX?PRESS) in SQL Server? Process sqlservr.exe is the...
What Are Date and Time Functions in MySQL? MySQL offers a number of functions for date and time valu...
How Fixed Length Strings Are Truncated and Padded in SQL Server Transact-SQL? When the length of the...