How to use the SUBSTR function in Oracle?

The SUBSTR function in Oracle is used to extract a substring from a string. Its syntax is as follows:

Retrieve a portion of the string starting from a specified position with an optional limit on the length.

The parameters are described as follows:

  1. String: the string from which to extract a substring.
  2. Starting position: the beginning position of the substring, with the first character being at position 1.
  3. Length (optional): the length of the substring to extract. If this parameter is not specified, the substring will include all characters from the starting position to the end of the string.

Here are some examples of using the SUBSTR function:

  1. Extract a substring from a string.
  2. Choose a portion of text starting from the seventh character in the phrase ‘Hello World’.
  3. Outcome: World
  4. Extract a substring of a specified length from a string.
  5. Choose the substring starting from the 7th character up to the 5 characters in ‘Hello World’.
  6. Result: World.
  7. Extract the last few characters of a string:
  8. Choose the last 5 characters of the string ‘Hello World’.
  9. Outcome: World

Please note that in Oracle, string positions are counted from one, not zero. If the specified starting position is greater than the length of the string, an empty string will be returned. If the specified starting position is negative, counting starts from the end of the string.

I hope the above information was helpful to you! If you have any other questions, please feel free to ask.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds