简体   繁体   中英

Oracle Stored Procedure into a View

I have a SP in oracle wich returns a cursor, before I had a query to create a viewn, but due to the complexity of the data I need, the better option to get it was a SP, but I strictly need the view with the information ( client's requirement), but now I have no idea how to put/convert the data (cursor) in the view, I was checking Global Temporary Tables, but that means I need to call the SP before accessing the view, and that's not possible. It's imperative that I call access the view with a select, Select * from view_data_sp, and obviously that the performance is not affected.

Any idea how can I achieve this?

Thanks

Consider using record type, table of records and pipe rows. Something like this would do the trick?

CREATE OR REPLACE package sysop as
  type file_list_rec is record(filename varchar2(1024));
  type file_list is table of file_list_rec;

  function ls(v_directory varchar2) return file_list pipelined;
end;
/

CREATE OR REPLACE package body sysop as
  function ls(v_directory varchar2) return file_list pipelined is
    rec file_list_rec;
    v_host_list varchar2(32000) := '';
  begin
    v_host_list := host_list(v_directory);

    for file in (
      select regexp_substr(v_host_list, '[^'||chr(10)||']+', 1, level)
        from dual
          connect by
            regexp_substr(v_host_list, '[^'||chr(10)||']+', 1, level) is not null)
      loop
        pipe row (file);
      end loop;
     return;
  end ls;
end sysop;
/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM