Skip to content

Instantly share code, notes, and snippets.

@qpgmr-de
Created September 15, 2023 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qpgmr-de/15da6300f0c8c7ac71129367218f0b14 to your computer and use it in GitHub Desktop.
Save qpgmr-de/15da6300f0c8c7ac71129367218f0b14 to your computer and use it in GitHub Desktop.
SQL user defined tabler function to slice a string
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