You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chore(query): Implement Oracle-compatible INSTR Function in Databend (#18084)
This PR implements Oracle-compatible `INSTR` string search functionality in Databend, supporting both three-parameter and four-parameter variants to enhance SQL compatibility with Oracle databases.
```sql
INSTR(string, substring [, pos] [, occurrence])
```
Finds the position of a substring within a string starting from a specified position.
**Parameters:**
- `string`: The input string to search within (can be NULL)
- `substring`: The substring to locate (can be NULL)
- `pos`: The starting position for the search (1-based index)
- Positive number: Search forward from left to right
- Negative number: Search backward from right to left
- Zero: Treated as 1 (start from beginning)
**Returns:**
- The 1-based position where the substring is found
- Returns 0 if:
- Either string or substring is NULL
- Substring is not found
- pos is 0 (after being converted to 1) and substring isn't at start
Finds the nth occurrence of a substring within a string starting from a specified position.
**Additional Parameter:**
- `occurrence`: Which occurrence of the substring to find (must be positive integer)
- 1 = first occurrence (default behavior)
- 2 = second occurrence, etc.
**Returns:**
- Same return rules as three-parameter version
- For occurrence > 1, continues searching after previous matches
- If occurrence exceeds actual number of matches, returns 0
0 commit comments