Home  >  Article  >  Database  >  Usage of substr in oracle

Usage of substr in oracle

下次还敢
下次还敢Original
2024-04-30 07:24:16430browse

SUBSTR function is used to extract substrings from strings. The syntax is SUBSTR(string, start, length). You need to specify the source string, starting position and length (optional), and the function extracts the substring of the specified length starting from the specified position. For example, SUBSTR('Hello World', 1, 5) returns "Hello" and SUBSTR('Hello World', 7) returns "World".

Usage of substr in oracle

Usage of SUBSTR function in Oracle

What is SUBSTR function?

SUBSTR function is used to extract substrings from strings.

Syntax:

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

Where:

  • string is the source string.
  • start is the starting position (starting from 1) to extract the substring.
  • length is the length of the substring.

Usage:

When using the SUBSTR function, you need to specify the following parameters:

  • string: The source string from which to extract the substring.
  • start: The character position from which to start extracting the substring. For the first character, start is 1.
  • length (optional): The length of the substring to be extracted. If not specified, all characters from the start position to the end of the string will be extracted.

Examples:

The following are some example usages of the SUBSTR function in Oracle:

<code>-- 从 "Hello World" 中提取 "Hello"
SELECT SUBSTR('Hello World', 1, 5) FROM dual;

-- 从 "Hello World" 中提取 "World"
SELECT SUBSTR('Hello World', 7) FROM dual;

-- 从 "Hello World" 中提取从第 7 个字符开始的所有文本
SELECT SUBSTR('Hello World', 7, LENGTH('Hello World') - 6) FROM dual;</code>

Note:

  • SUBSTR function counts characters starting from 1.
  • If start or length is negative, an empty string is returned.
  • If start is greater than the string length, an empty string is returned.
  • If length is longer than the length of the remaining string, return the remaining string.

The above is the detailed content of Usage of substr 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:date usage in oracleNext article:date usage in oracle