Instr Function In Sql in SQL
INSTR Function in SQL
The INSTR function returns the position of the first occurrence of a substring within a string. If the substring is not found, it returns 0.
Syntax:
INSTR(string, substring)string: The string to search within.substring: The substring to find.
Example:
SELECT INSTR('Hello World', 'World') AS position;Result:
| position |
|---|
| 7 |
Explanation: The substring 'World' starts at the 7th character in 'Hello World'.
Notes:
The position count usually starts at 1 (not 0).
If substring is not found, returns 0.
Supported in MySQL, Oracle, and some other databases (syntax may vary slightly).
Variant in Some Databases:
In SQL Server, use
CHARINDEX(substring, string)instead.In Oracle,
INSTR(string, substring [, start_position [, occurrence]])supports additional options.
If you want examples for a specific database or advanced usage, just ask!