Advertisement
RomioSul

GET_SplittedStrings_fn

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