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 commonly used methods are as follows (here we use SUBSTR () as an example):
SUBSTR (str, POS)
From <str>, select all characters starting with the <pos> position. Please note that this syntax does not apply to SQL Server.
SUBSTR (str, POS, len)
Starting with the <pos> position in <str>, select the next <len> characters.
Suppose 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 is measured as follows:
reprint Please specify: Xiao Liu
A concise tutorial of SQL statements for Linux---SUBSTRING