Table-Valued Functions in ORACLE 11g ? ( parameterized views )

前端 未结 3 999
旧时难觅i
旧时难觅i 2020-12-03 03:37

I\'ve seen discussions about this in the past, such as here. But I\'m wondering if somewhere along the line, maybe 10g or 11g (we are using 11g), ORACLE has introduced any b

3条回答
  •  借酒劲吻你
    2020-12-03 04:33

    No need for SYS_CONTEXT or cursor definitions. You do need a type so that, when the SQL is parsed, it can determine which columns are going to be returned. That said, you can easily write a script that will generate type and collection type definitions for one or more tables based on the data in user_tab_columns.

    The closest is

    create table my_table
    (prodid number, a varchar2(1), b varchar2(1), 
      c varchar2(1), d varchar2(1), e varchar2(1));
    
    create type my_tab_type is object
    (prodid number, a varchar2(1), b varchar2(1), 
      c varchar2(1), d varchar2(1), e varchar2(1))
    .
    /
    
    create type my_tab_type_coll is table of my_tab_type;
    /
    
    create or replace function get_some_data (p_val in number) 
    return my_tab_type_coll pipelined is
    begin
      FOR i in (select * from my_table where prodid=p_val) loop
        pipe row(my_tab_type(i.prodid,i.a,i.b,i.c,i.d,i.e));
      end loop;
      return;
    end;
    /
    
    SELECT * FROM table(get_Some_Data(3));
    

提交回复
热议问题