Embarking on your learning journey of Oracle SQL? W3Schools, known for its interactive and easy-to-understand tutorials, offers an excellent platform to grasp the intricacies of the INSTR function in Oracle SQL. The INSTR function in Oracle SQL, as you'll soon discover, is a powerful tool for string manipulation. Let's delve into it.

Before we dive into the specifics, ensure your Oracle SQL environment is set. W3Schools provides a free 'try it yourself' Oracle online editor for you to practice directly with the examples we'll discuss. So, let's get started, shall we?

Understanding the INSTR Function
The INSTR function is used to find the position of the first occurrence of a substring in another string. It starts searching from the first character of the main string.

Remember, the position of the first occurrence is not zero-based. Instead, it starts from 1, as in Oracle SQL, counting begins with the first character.
The Syntax

The basic syntax of the INSTR function is: INSTR(string, substring [, start_position] )
The 'start_position' is optional. If specified, INSTR begins the search from the start_position.
Basic Usage

Let's see a basic usage: Assume 'ORACLE' is our main string, and 'C' is the character we're looking for. INSTR('ORACLE', 'C') returns 3, which is the position of 'C' in 'ORACLE'.
If the character is not found, INSTR returns 0. For example, INSTR('ORACLE', 'Z') returns 0.
Advanced Features of INSTR Function

As you become comfortable with the basics, let's explore the advanced features. The INSTR function allows us to specify the starting position to search for the substring.
Moreover, it can return the position of a substring's last occurrence in a string.



















Start Position and ' -(Negative Number)' Behavior
If you specify a start position, INSTR begins the search from there. For instance, INSTR('ORACLE', 'C', 2) returns 2, which is the position of the second 'C' in 'ORACLE'.
If you specify a start position as -(negative number), INSTR starts the search from the end of the string. For example, INSTR('ORACLE', 'C', -3) returns 7, the position of 'C' from the end of 'ORACLE'.
Finding the Last Occurrence
To find the last occurrence of a substring in a string, you can use INSTR with the ' -(negative number)' start position. Let's try INSTR('ORACLE', 'C', -1). It returns 7, which is the last occurrence of 'C'.
If the substring is not found, Oracle SQL returns null.
That wraps up our exploration of the INSTR function. As with learning anything, practice makes perfect. W3Schools offers a wealth of exercises for you to plug in and practice directly with your Oracle SQL editor. Happy coding!