search
Homephp教程PHP开发Detailed explanation of Oracle custom split function examples

Oracle custom split function

Oracle does not provide a split function, but you can create a function yourself to achieve this function. For example, "abc defg hijkl nmopqr stuvw xyz", the separator is a space, but the number of spaces is variable.

Source code:

CREATE OR REPLACE TYPE ty_str_split IS TABLE OF VARCHAR2 (4000);
 
CREATE OR REPLACE FUNCTION fn_var_split (
  p_str IN VARCHAR2,
  p_delimiter IN VARCHAR2
)
  RETURN ty_str_split
IS
  j INT := 0;
  len INT := 0;
  str VARCHAR2 (4000);
  str_split ty_str_split := ty_str_split ();
  v_str VARCHAR2 (4000) := RTRIM (LTRIM (p_str, p_delimiter), p_delimiter);
BEGIN
  len := LENGTH (v_str);
 
  WHILE len > 0
  LOOP
    j := INSTR (v_str, p_delimiter, 1);
 
    IF j = 0
    THEN
      str := SUBSTR (v_str, 1);
      len := 0;
      str_split.EXTEND;
      str_split (str_split.COUNT) := str;
    ELSE
      str := SUBSTR (v_str, 1, j - 1);
      v_str := LTRIM (LTRIM (v_str, str), p_delimiter);
      len := LENGTH (v_str);
      str_split.EXTEND;
      str_split (str_split.COUNT) := str;
    END IF;
  END LOOP;
 
  RETURN str_split;
END fn_var_split;
/

Test:
Result:

1
12
123
1234
12345
DECLARE
  CURSOR c
  IS
    SELECT * FROM TABLE (CAST (fn_var_split (';1;12;;123;;;1234;;;;12345;', ';') AS ty_str_split));
  r c%ROWTYPE;
BEGIN
  OPEN c;
  LOOP
    FETCH c INTO r;
    EXIT WHEN c%NOTFOUND;
    DBMS_OUTPUT.put_line (r.column_value);
  END LOOP;
  CLOSE c;
END;
/

Thank you for reading, I hope it can help everyone, thank you for your support of this site!

For more Oracle custom split function examples and related articles, please pay attention to 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software