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

Function to intercept string in oracle

下次还敢
下次还敢Original
2024-05-03 00:24:511115browse

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>

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>

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!

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
Previous article:exception usage in oracleNext article:exception usage in oracle