Home > Database > Oracle > body text

Usage of substr function in oracle

下次还敢
Release: 2024-04-30 08:27:15
Original
759 people have browsed it

The substr() function extracts a substring of a string. The syntax is: substr(str, start, [length]). Usage example: Extract the 4 characters starting from the 3rd character from 'Hello World': SELECT substr('Hello World', 3, 4) FROM dual; Result: 'llo'.

Usage of substr function in oracle

Usage of substr() function in Oracle

The substr() function is used to extract substrings from strings . The syntax is as follows:

<code>substr(str, start, [length])</code>
Copy after login

Where:

  • str: The string from which the substring is to be extracted.
  • start: Extract the starting position of the substring, counting from 1.
  • length (optional): The length of the substring to be extracted. If omitted, everything from the starting position to the end of the string is extracted.

Usage example

<code>SELECT substr('Hello World', 3, 4) FROM dual;</code>
Copy after login

Output:

<code>llo </code>
Copy after login

Example description:

  • This query extracts a 4-character substring starting from the 3rd character ('l') from the string 'Hello World'.
  • The result substring is "llo".

Other usage examples:

  • Extract the first character of the string:

    <code>SELECT substr('Oracle', 1, 1) FROM dual;</code>
    Copy after login
  • Extract the last few characters of the string:

    <code>SELECT substr('Database', -3) FROM dual;</code>
    Copy after login
  • Extract the substring of the specified length:

    <code>SELECT substr('Programming', 1, 8) FROM dual;</code>
    Copy after login

Note:

  • start parameter must be greater than or equal to 1.
  • length parameter must be greater than or equal to 0.
  • If start length > string length, only the characters from start to the end of the string will be extracted.
  • If start or length is negative, NULL will be returned.

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!