Linux SQL statement concise tutorial --- SUBSTRING, linux concise tutorial
The substring function in SQL is used to capture part of a column. The function names are not exactly the same in different databases:
- MySQL: SUBSTR (), SUBSTRING ()
- Oracle: SUBSTR ()
- SQL Server: SUBSTRING ()
The most common method is as follows (Here we use SUBSTR () as an example ):
SUBSTR (str, pos)
Select All characters starting from position <pos> in <str>. Note that this syntax is not applicable to SQL Server.
SUBSTR (str, pos, len)
Start from the <pos> position in <str> and select the <len> character.
Suppose we have the following table:
GeographyTable
Region_Name |
Store_Name |
East |
Boston |
East |
New York |
West |
Los Angeles |
West |
San Diego |
Example 1
Select substr (Store_Name, 3)
FROM Geography
WHERE Store_Name = 'Los Angeles ';
Result:
'S Angeles'
Example 2
Select substr (Store_Name, 2, 4)
FROM Geography
WHERE Store_Name = 'san Diego ';
Result:
'An d'
Linux has been tested as follows:
Reprinted, please note: Xiao Liu