Created
September 29, 2023 17:10
-
-
Save xtender/003dcedcf3e6e451e50983f9f782ed5e to your computer and use it in GitHub Desktop.
Example of splitting strings using SQL_MACRO for Oracle 19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with t as (select 'aaa,asdf,2,3,3,4,5,,123,,,zz' s from dual) | |
select * | |
from t outer apply str_split(t.s, ',') | |
/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace function str_split(str varchar2, delimiter varchar2) | |
return varchar2 sql_macro | |
is | |
begin | |
return q'{ | |
select | |
level as n | |
,regexp_substr( | |
s | |
,'([^'||delimiter||']*)['||delimiter||']' | |
,1 | |
,level | |
,'' | |
,1) as substring | |
from (select str||delimiter as s from dual) v | |
connect by level<=regexp_count(s,delimiter) | |
}'; | |
end; | |
/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://dbfiddle.uk/DBcKnVBJ