Home  >  Article  >  Database  >  How to use split() function in oracle

How to use split() function in oracle

下次还敢
下次还敢Original
2024-05-07 13:06:161265browse

The SPLIT() function splits a string into an array by the specified delimiter, returning a string array where each element is a delimiter-separated part of the original string. Usage includes: splitting a comma-separated list of values ​​into an array, extracting filenames from paths, and splitting email addresses into usernames and domains.

How to use split() function in oracle

SPLIT() function in Oracle

The SPLIT() function is used to separate strings by specified symbols into arrays. The syntax is as follows:

<code>SPLIT(string, delimiter)</code>

Parameters:

  • string: The string that needs to be split
  • delimiter: The delimiter used to split the string

Return value:

Returns an array of strings in which each element is the delimiter-delimited portion of the original string.

Usage:

The SPLIT() function can be used to solve various string processing tasks, for example:

  • Comma separated list of values ​​split into array:

    <code>SELECT SPLIT('name1,name2,name3', ',') FROM dual;</code>
  • Extract filename from path:

    <code>SELECT SPLIT('path/to/filename.ext', '/')[-1] FROM dual;</code>
  • Split email address into Username and Domain:

    <code>SELECT SPLIT('username@domain.com', '@')[1] FROM dual;</code>

Notes:

  • The delimiter can be a single character or a string.
  • If no delimiter exists in the original string, an array containing a single element is returned, which is the original string.
  • If the delimiter is NULL, split the string into an array with one element per character.

The above is the detailed content of How to use split() function 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