Home >Database >Oracle >Usage of substring in oracle

Usage of substring in oracle

下次还敢
下次还敢Original
2024-04-30 08:57:16755browse

The SUBSTRING function in Oracle is used to extract the specified part from a string. Syntax: SUBSTRING(string, start, length). Parameters: string - the string to extract the substring; start - the starting position of the substring; length (optional) - the length of the substring. Usage: 1. Specify the starting position and length: such as SUBSTRING('Hello World', 3, 6) returns "llo Wo"; 2. Specify the starting position without specifying the length: such as SUBSTRING('Hello World', 3) Return "llo Wor

Usage of substring in oracle

##Usage of SUBSTRING function in Oracle

##Definition

The SUBSTRING function extracts a specified portion from the given string.

Syntax

<code>SUBSTRING(string, start, length)</code>

Parameters

    string:
  • The string to extract the substring from.
  • start:
  • The position in the string to start extracting the substring from. #length (optional): The length of the substring to extract. If omitted, the substring from the given position to the end of the string is extracted. ##How to use SUBSTRING
Specify the starting position and length

For example, to extract from the "Hello World" string, start at position 3 of 6 characters, you can use the following code:

<code>SUBSTRING('Hello World', 3, 6)</code>
This will return the substring "llo Wo"
  1. Specify the starting position without specifying. Length

    For example, to extract the substring starting at position 3 from the "Hello World" string, you can use the following code:

    <code>SUBSTRING('Hello World', 3)</code>
    This will return the substring "llo World" .
  2. Truncate the end of the string

    For example, to truncate the last 3 characters from the "Hello World" string, you can use the following code:

    <code>SUBSTRING('Hello World', LENGTH('Hello World') - 2)</code>
    This will return the substring "rld"
  3. ##Tip

    Positional parameters start with 1, instead of 0.

  4. If the supplied starting position exceeds the length of the string, SUBSTRING will return an empty string.

If the supplied length is negative, SUBSTRING will return an empty character. String.

You can use the NEGATIVE parameter to extract a substring starting from the end of the string. For example:
    <code>SUBSTRING('Hello World', -3)</code>
  • This will return the substring "rld".
  • ##

    The above is the detailed content of Usage of substring in oracle. For more information, please follow other related articles on the PHP Chinese website!

    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn