Oracle SUBSTR Function Guide

In Oracle, you can use the SUBSTR function to extract a substring. The syntax for the SUBSTR function is as follows:

Extract a substring from the specified string, starting at a certain position and with a certain length.

In this case, the string represents the original string to be extracted, the start position indicates from which point in the original string to begin extracting, and the length indicates the length of the substring to be extracted.

Here are some examples:

  1. Extract the first 3 characters from the string:
    SELECT SUBSTR(‘Hello World’, 1, 3) FROM dual;
    Result: Hel
  2. Retrieve the characters from the 4th to the 7th position in the string:
    SELECT SUBSTR(‘Hello World’, 4, 4) FROM dual;
    Result: lo W
  3. Extract the last 5 characters of a string:
    SELECT SUBSTR(‘Hello World’, -5) FROM dual;
    Result: World

Please note that the starting position can be negative, indicating counting from the end of the string. If the length parameter is omitted, it defaults to cutting all characters from the starting position to the end of the string.

bannerAds