Home > Database > Oracle > Function to intercept string in oracle

Function to intercept string in oracle

下次还敢
Release: 2024-05-03 00:24:51
Original
1190 people have browsed it

Oracle provides two string interception functions: substr(): intercepts characters of the specified length starting from the specified position. substring(): intercept the remaining characters from the specified position, or intercept the characters of the specified length from the specified position.

Function to intercept string in oracle

String interception function in Oracle

In order to facilitate the interception of strings, Oracle provides two functions, substr() and substring. (), their usage is similar.

substr(string, start, length)

Truncate length characters starting from the start character from the string string.

Example:

<code class="sql">SELECT substr('Hello World', 6, 5) FROM dual;
-- 输出:World</code>
Copy after login

substring(string, start [, length])

Intercept from string string A string starting with the start character. If length is not specified, truncates to the end of the string.

Example:

<code class="sql">SELECT substring('Hello World', 6) FROM dual;
-- 输出:World

SELECT substring('Hello World', 2, 3) FROM dual;
-- 输出:ell</code>
Copy after login

Note:

  • start parameter starts from 1, indicating the number 1 in the string a character.
  • If start or length is negative, the function returns an empty string.
  • If start exceeds the string length, the function will return an empty string.
  • If length exceeds the length of the string, the function will truncate to the end of the string.

The above is the detailed content of Function to intercept string 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 Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template