This function is used to return the substring of str, starting from start_position and with a length of length.
substr(string <str>, bigint <start_position>[, bigint <length>])
or
substring(string <str>, bigint <start_position>[, bigint <length>])
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
str |
Yes |
STRING |
If the value is of the BIGINT, DECIMAL, DOUBLE, or DATETIME type, the value is implicitly converted to the STRING type for calculation. |
start_position |
Yes |
BIGINT |
Start position. The default value is 1. If the value is positive, the substring is returned from the left. If the value is negative, the substring is returned from the right. |
length |
No |
BIGINT |
Length of the substring. The value must be greater than 0. |
The return value is of the STRING type.
The value k SQL is returned.
SELECT substr('Spark SQL', 5);
The value SQL is returned.
SELECT substr('Spark SQL', -3);
The value k is returned.
SELECT substr('Spark SQL', 5, 1);