This function is used to return the index of substr that appears earliest in str.
It returns NULL if either of the arguments are NULL and returns 0 if substr does not exist in str. Note that the first character in str has index 1.
Similar function: instr1. The instr1 function is used to calculate the position of the substring str2 in the string str1. The instr1 function allows you to specify the start search position and the number of matching times.
instr(string <str>, string <substr>)
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
str |
Yes |
STRING |
Target string to be searched for If the value is of the BIGINT, DOUBLE, DECIMAL, or DATETIME type, the value is implicitly converted to the STRING type for calculation. For other types of values, an error is reported. |
substr |
Yes |
STRING |
Substring to be matched If the value is of the BIGINT, DOUBLE, DECIMAL, or DATETIME type, the value is implicitly converted to the STRING type for calculation. For other types of values, an error is reported. |
The return value is of the BIGINT type.