I need to write a procedure to normalize a record that have multiple tokens concatenated by one char. I need to obtain these tokens splitting the string and insert each one as a new record in a table. Does Oracle have something like a "split" function?
相关问题
- how to split a list into a given number of sub-lis
- Generate string from integer with arbitrary base i
- Can I skip certificate verification oracle utl_htt
- Can I skip certificate verification oracle utl_htt
- Converting a string array to a byte array
Please find next an example you may find useful
--1st substring
--2nd substring
--3rd substring
--4th substring
Best regards
Emanuele
There is
apex_util.string_to_table
- see my answer to this question.Also, prior to the existence of the above function, I once posted a solution here on my blog.
Update
In later versions of APEX,
apex_util.string_to_table
is deprecated, and a similar function apex_string.split is preferred.If
APEX_UTIL
is not available, you have a solution usingREGEXP_SUBSTR()
.Inspired from http://nuijten.blogspot.fr/2009/07/splitting-comma-delimited-string-regexp.html :
You can use regexp_substr(). Example:
The query iterates through the comma separated string, searches for the comma (,) and then splits the string by treating the comma as delimiter. It returns the string as a row, whenever it hits a delimiter.
level
in statementregexp_substr('SMITH,ALLEN,WARD,JONES','[^,]+', 1, level)
refers to a pseudocolumn in Oracle which is used in a hierarchical query to identify the hierarchy level in numeric format: level in connect byYou could use a combination of SUBSTR and INSTR as follows :
Example string :
field = 'DE124028#@$1048708#@$000#@$536967136#@$'
The seperator being #@$.
To get the '1048708' for example :
If the field is of fixed length ( 7 here ) :
If the field is of variable length :
You should probably look into SUBSTR and INSTR functions for more flexibility.