How to extract specific content from an Oracle string?

To extract specific content, you can use the SUBSTR function. This function is used for extracting substrings from a string.

Syntax:
SUBSTR(string, start_position, length)

Explanation of parameters:

  1. string: the string to be extracted.
  2. start_position: specifies the character at which to begin the extraction. Position numbering starts at 1.
  3. length: an optional parameter that specifies the length of the substring to be extracted. If no length is specified, all characters from the starting position to the end of the string will be extracted.

For instance, if we have a string “Hello World” and we want to extract the “World” part, we can use the following code:

SELECT SUBSTR('Hello World', 7) FROM dual;

The output result is “World”.

One can specify the starting position and length when wanting to extract a portion of a string. For example, to extract the “Hello” portion from the string “Hello World”, you can use the following code:

SELECT SUBSTR('Hello World', 1, 5) FROM dual;

The output is “Hello”.

bannerAds