Created
September 15, 2023 16:23
-
-
Save qpgmr-de/15da6300f0c8c7ac71129367218f0b14 to your computer and use it in GitHub Desktop.
SQL user defined tabler function to slice a string
This file contains 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 slice | |
( | |
input_string clob(1048576), | |
output_size int | |
) | |
returns table ( | |
ordinal_position bigint, | |
element clob(1048576) | |
) | |
language sql | |
no external action | |
not fenced | |
statement deterministic | |
program name slice | |
returns null on null input | |
begin | |
declare idx int default 0; | |
while (output_size <> 0) and (idx * output_size) < length(input_string) | |
do | |
pipe (idx + 1, substring(input_string || space(output_size) || '$', idx * output_size + 1, output_size)); | |
set idx = idx + 1; | |
end while; | |
return; | |
end; | |
label on routine slice is 'Slice string into parts'; | |
comment on parameter routine slice ( | |
input_string is 'Input String', | |
output_size is 'Length of Parts' | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment