How to extract substrings based on specific characters in oracle?

In Oracle database, you can use the SUBSTR function to extract a specific number of characters from a string.

The specific grammar is as follows:

SUBSTR(string, start_position, length)
  1. String: The string to be extracted.
  2. start_position: The position at which the extraction should begin. It can be a positive or negative integer. Positive integers indicate counting from the left side of the string, while negative integers indicate counting from the right side of the string.
  3. Number of characters to be extracted.

Here are some examples:

  1. Retrieve the first 3 characters from the left side of the string.
SELECT SUBSTR('Hello, World!', 1, 3) FROM dual;

The output is “Hel”

  1. Retrieve the last 4 characters of a string starting from the right side.
SELECT SUBSTR('Hello, World!', -4, 4) FROM dual;

The output result is “ld!”

  1. Extract a portion of the string starting from a specified position.
SELECT SUBSTR('Hello, World!', 8, 5) FROM dual;

The output is “World”.

广告
Closing in 10 seconds
bannerAds