Advertisement
RomioSul

GET_SplittedIDs

Jun 6th, 2021
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. create or replace function public.GET_SplittedIDs_fn(
  2.     pSource    varchar,
  3.     pSplitter  varchar(10)
  4. )
  5. returns  table(data_n integer, data_item integer)
  6. language plpgsql
  7. AS $$
  8. BEGIN
  9.     DECLARE
  10.     n integer;
  11.     p integer;
  12.     value integer;
  13. begin
  14.     WHILE LEN(pSource) > 0 loop
  15.         select p = strpos(pSource, pSplitter);
  16.         if p = 0 then
  17.         select p = LEN(pSource) + 1;
  18.         end if;
  19.         value = cast(LEFT(pSource, p-1) as integer);
  20.         insert into data select value;
  21.         pSource = SUBSTRING(pSource,p+1, LEN(pSource));
  22.         n=n+1;
  23.     END loop;
  24.     return;
  25.     end;
  26. END;
  27. $$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement