The substring function in SQL is used to grab a portion of a field data. The name of this function is not exactly the same in different repositories:
- Mysql:substr (), SUBSTRING ()
- Oracle:substr ()
- SQL server:substring ()
The most frequently used methods are the following (here we use SUBSTR () for example):
SUBSTR (str, POS)
From <str>, select all characters starting from the <pos> position. Please note that this syntax does not apply to SQL Server.
SUBSTR (str, POS, len)
From the <str> <pos> position, select the next <len> characters.
If we have the following table:
Geography Form
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 ';
Results:
' s Angeles '
Example 2
SELECT SUBSTR (Store_name, 2, 4)
From Geography
WHERE store_name = ' San Diego ';
Results:
' an D '
Linux measurements such as the following:
reprint Please specify: Xiao Liu
A concise tutorial of SQL statements for Linux---SUBSTRING