oracel中字符串分割成集合详解
文章分享一篇关于自己的学习笔记,oracel中字符串分割成集合详解有需要学习的同学可以看看。
首先分别使用两种方式构造两个函数
代码如下 | 复制代码 |
-- use conventional plsql return l_list; -- use single sql return l_list; |
确认两种方法完成同样的功能
----------------------------------------------------
代码如下 | 复制代码 |
-- same result SQL> set serveroutput on
|
我们知道在PL/SQL和SQL里面,varchar2类型的长度限制是不同的。那么这两种方法是否也存在同样的限制?验证一下
先测试PL/SQL版本
-- 这里使用单个字母作为元素,加上必要的逗号分割符,一个元素占用长度2. PL/SQL中上限32767。当取(32767/2 = 16383)个元素的时候,运行成功
----------------------------------------------------
代码如下 | 复制代码 |
-- pls versions tring length limit l_list := f_str2list_pls(l_str, ','); PL/SQL procedure successfully completed |
代码如下 | 复制代码 |
declare l_list := f_str2list_pls(l_str, ','); ORA-06502: PL/SQL: numeric or value error: character string buffer too small -- 修改一下代码,实际调用这个函数。从结果可以看到,f_str2list_pls()内部报超长错误 l_list := f_str2list_pls(l_str||',a', ','); |
下面测试SQL版本
代码如下 | 复制代码 |
-- 因为SQL中varchar2上限是4000,所以使用2000个元素。一切正常。 l_list := f_str2list_sql(l_str, ','); PL/SQL procedure successfully completed |
代码如下 | 复制代码 |
declare l_list := f_str2list_sql(l_str, ','); |
测试比较两种方式在不同数据量下的性能
代码如下 | 复制代码 |
---------------------------------------------------- -- warm up before actually calculation
|
我们分别测试当元素个数为100, 200, 500, 1000, 2000的情况。每种情况进行3-5次然后取平均
元素个数
PL/SQL 运行时间 (1/100 second)
SQL 运行时间 (1/100 second)
PCT
100
1
1
100%
200
1
1 - 2
50% - 100%
500
1 - 2
2 - 3
30% - 50%
1000
1
4
25%
2000
2
10
20%
总结:
SQL版本的书写简便,并且可以脱离PL/SQL环境直接使用(单条SQL进行行列转换)。
SQL版本只能处理长度小于4000的字符串,实际最大只能包含2000个元素。PL/SQL版本可以处理长度小于32767的字符串。
小数据量情况下,两者性能相当。随着数据量增大,PL/SQL版本性能明显占优

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Python is a popular programming language that provides many built-in functions to handle strings. One of the commonly used functions is the split() function, which can split a string into multiple substrings according to the specified delimiter. This article will introduce how to use the split() function in Python3.x. In Python, the split() function is a built-in function of the string class. Its basic syntax is as follows: string.split(separator,maxsplit)

In the PHP language, there are many basic functions that can help us process strings quickly and efficiently. Among them, the explode function is a very practical string splitting function. It can split a string into arrays according to the specified delimiter, and then perform more flexible string operations. In this article, we will introduce how to use the explode function to split strings in PHP. 1. The format of the explode function. The format of the explode function in the PHP language is as follows: explode(separa

In this article, we will explore the problem of how to find the length of the maximizing partition of a string with unique characters. We first understand the problem statement and then study naive and efficient methods to solve this problem, including their respective algorithms and time complexities. Finally, we will implement the solution in C++. Problem Statement Given a string, split the string into as many substrings as possible so that each character in the string appears in only one substring. Returns the length of these maximizing splits. Naive approach The naive approach is to iterate through the string, recording the last occurrence of each character. Then, iterate over the string again and create a partition when the last occurrence of the current character is found. Algorithm (naive) to initialize an array to store strings in

How to Split String into Array in PHP In PHP, we often need to process strings and split them into multiple parts. Splitting a string into an array is a common operation that helps us better handle the various parts of the string. In this article, we will learn how to split a string into an array using functions in PHP and provide some code examples. Use the explode function to split a string into an array. PHP provides a function called explode, which can split the string according to the specified delimiter.

In this problem, we will calculate the way to divide the given string into K substrings such that it satisfies the conditions given in the problem statement. We will use recursion to solve this problem. Additionally, we will use tabular dynamic programming methods to efficiently solve this problem. Problem Statement − We have a string of specific length called bin_Str. The string contains only numeric characters from '0' to '9'. We need to calculate the number of ways to split the string into K substrings such that it satisfies the following conditions. Substring should contain at least 2 characters. The first character of each substring should be even and the last character should be odd. ExampleExample inputM=2,K=2;bin_str="255687&q

There are many string functions in PHP, among which the string splitting function is very commonly used. The string split function can split a string according to the specified delimiter and return an array. Below we will introduce several commonly used string splitting functions. explode function The explode function can split a string according to the specified delimiter and return an array. The syntax is as follows: explode(string$separator,string$string

The method to solve the error reported by the explode function in PHP requires specific code examples. In PHP, the explode function is a function used to split a string into an array according to the specified delimiter. However, sometimes an error occurs when using the explode function, mainly because the parameters passed in do not meet the requirements of the function. Below we will discuss possible problems and solutions in detail, and provide specific code examples. Error caused by wrong number of parameters when using explode function

In this problem, we need to split the given string such that the third substring can be a substring of the first two substrings. Let's think of a solution. The third string can be a substring of the first two strings only if the first two strings contain all the characters of the third string. So, we need to find at least one character with frequency greater than 3 in the given string, and we can take the third substring of that single character. Problem Statement - We are given a string str containing N lowercase alphabetic characters. We need to check if we can split the string into three substrings a, b and c such that substring c is a substring of a and b. Depending on whether 3 substrings can be found, print "yes" or "no"
