Syntax for SUBSTRING: SUBSTRING(expression, start, length)
Expression
String, binary string, text, image, column, or expression that contains a column. Do not use expressions that contain aggregate functions.
Start
An integer or expression that can be implicitly converted to an int indicates the start position of the substring.
Length
An integer or expression that can be implicitly converted to an int value refers to the length of the stator string.
Example:
1. The starting position is 0 and the truncation length is 3.
select substring(DWMC,0,3) as Sub,DWMC as DWMC from DW where DWNM='00010010'
Result:
2. The starting position is 1 and the truncation length is 3.
select substring(DWMC,1,3) as Sub,DWMC as DWMC from DW where DWNM='00010010'
Result:
3. The starting position is-1 and the truncation length is 3.
select substring(DWMC,-1,3) as Sub,DWMC as DWMC from DW where DWNM='00010010'
Result:
4. The starting position is-2 and the truncation length is 3.
select substring(DWMC,-2,3) as Sub,DWMC as DWMC from DW where DWNM='00010010'
Result:
5. The starting position is-9, and the truncation length is 3.
select substring(DWMC,-9,3) as Sub,DWMC as DWMC from DW where DWNM='00010010'
Result:
Through the above example, we can see that the truncation of the substring is similar to the absolute length on the X coordinate. For the string, the position of negative number and zero is empty, there are actually several locations starting from 1!