0
begin
      lcl_sql_stmt := 'SELECT trim(regexp_substr(''' || pmotn_id_array || ''', ''[^,]+'', 1, LEVEL)) ' ||
      'FROM dual ' ||
      'CONNECT BY LEVEL <= instr(''' || pmotn_id_array || ''', '','', 1, LEVEL - 1)';
      open pmotn_cur for execute lcl_sql_stmt;
     
     
      close pmotn_cur;
end;

I am trying to migrate oracle code to postgres sql. I am trying to understand what this query does and its equivalent in postgres

MT0
  • 143,790
  • 11
  • 59
  • 117
  • "I am trying to understand what this query does" It converts `pmotn_id_array`, a comma delimited string, to a cursor containing the items in the delimited list in each row. – MT0 May 31 '22 at 22:01
  • `SELECT token FROM unnest(string_to_array('a,b,c,d', ',')) token` [db<>fiddle](https://dbfiddle.uk/?rdbms=postgres_14&fiddle=bedd741394d22dfa7b27bb9e890e4690) – MT0 May 31 '22 at 22:08

0 Answers0