Home> Database> Oracle> body text

Usage of substr function in oracle

下次还敢
Release: 2024-04-30 08:27:15
Original
560 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:

substr(str, start, [length])
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

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

Output:

llo 
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:

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

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

    SELECT substr('Programming', 1, 8) FROM dual;
    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
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!