instr
The instr function is used to return the earliest occurrence index of substr in str.
When a parameter is NULL, NULL is returned. When substr does not exist in str, 0 is returned. Note that the index starts from 1.
Similar function: instr1. The instr1 function calculates the position of substring str2 in string str1. The instr1 function supports specifying a starting search position and the occurrence count.
Syntax
instr(string , string )
Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| str | Yes | STRING | The target string to be searched. If the input is of type BIGINT, DOUBLE, DECIMAL, or DATETIME, it is implicitly converted to STRING type before evaluation. Other types will return an error. |
| substr | Yes | STRING | The substring to be matched. If the input is of type BIGINT, DOUBLE, DECIMAL, or DATETIME, it is implicitly converted to STRING type before evaluation. Other types will return an error. |
Return Values
Returns a value of type BIGINT.
- If str2 is not found in str1, 0 is returned.
- If str2 is an empty string, it always matches successfully. For example, select instr('abc',''); returns 1.
- If str1 or str2 is NULL, NULL is returned.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot