Function:Returns part of a character, binary, text, or image expression.
Syntax:Substring (expression, start, length)
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 ()
Parameters:
Expression string, binary string, text, image, column, or expression that contains a column. Do not use expressions that contain aggregate functions.
The START integer or expression that can be implicitly converted to int, which indicates the start position of the stator string.
An integer or expression that can be implicitly converted to an int. It refers to the length of the substring.
-
return value:
-
If expression is a supported character data type, character data is returned. If expression is a supported binary data type, binary data is returned. If start = 1, the substring starts with the first character of the expression.
the type of the returned string is the same as that of the given expression (except for the content shown in the following table ).
given expression |
return type |
image |
varbinary |
ntext |
nvarchar |