Skip to Main Content

Apex_string.split is slow

Try to avoid apex_string.split in queries whenever performance is important.
Recently I modified a query from using apex_string.split to using instr, and it was 20 times faster after that.

The example below gives you an idea how that looks (use e.g. "10:20" for :P_DEPTNO) - but of course you need a more complex query to notice any performance changes:

Listagg (reversed)

Listagg (reversed) for strings

Value
A
B
C
D
E
F
G

Listagg (reversed) for numbers

Value
1
2
3
4
5
6
7
Two solutions for a SQL version of the apex_string.split (or apex_util.string_to_table in older Apex versions) PL/SQL function, for both strings and numbers.
I needed a pure SQL version to create insert statements with; of course I could have used a PL/SQL procedure but this was a lot simpler. And it performs very well.
Change the : to whatever you need, and remove the distinct if needed.

Note that apex_util.string_to_table was only introduced with Apex 5.1 (and apex_string.split in a later version), so I have also include the "OLD" code sections for older versions which use xmltable (and work just as well, but may be slower).

Code

Region

Identification
Sequence
Title
Type
Source
Source Type
Region Source

Region

Identification
Sequence
Title
Type
Source
Source Type
Region Source