2011-01-19 133 views
1

我如何使下列包裝選擇所有列「*」而不是隻有if_typenumber_infectedPL SQL如何選擇所有列

--spec 
create or replace package WrapperSample is 

    type TResultRow is record(
    if_type   codes.cd%type 
    ,number_infected Integer); 

    type TResultRowList is table of TResultRow; 

    function GetADedIcWarningsProv 
    (
    p_hos_id in work_entity_data.hos_id%type 
    ,p_date in date 
) return TResultRowList 
    pipelined; 

end WrapperSample; 
/

--body 
create or replace package body WrapperSample is 

    function GetADedIcWarningsProv 
    (
    p_hos_id in work_entity_data.hos_id%type 
    ,p_date in date 
) return TResultRowList 
    pipelined is 
    v_refcur eOdatatypes_package.eOrefcur; 
    currentRow TResultRow; 
    begin 
    v_refcur := YourSchema.getADedIcWarningsProv(p_hos_id, p_date); 

    loop 
     fetch v_refcur 
     INTO currentRow; 
     exit when v_refcur%NotFound; 
     pipe row(currentRow); 
    end loop; 

    close v_refcur; 

    return; 
    end; 

end WrapperSample; 
/

回答

5

我不知道我是否瞭解您的問題和要求。

但是,如果你正在尋找一種方式來獲得一個表的內容,或它的一部分,這可能是你將如何處理它:

create table tq84_test_table (
    col_1 number, 
    col_2 varchar2(10), 
    col_3 date 
); 

insert into tq84_test_table values (1, 'one' , sysdate); 
insert into tq84_test_table values (2, 'two' , sysdate+1); 
insert into tq84_test_table values (3, 'three', sysdate-1); 


create or replace package tq84_sss as 

    type record_t is table of tq84_test_table%rowtype; 

    function GetADedIcWarningsProv return record_t; 

end; 
/

create or replace package body tq84_sss as 

    function GetADedIcWarningsProv return record_t 
    is 
     ret record_t; 
    begin 

     select * bulk collect into ret 
     from tq84_test_table; 

     return ret; 

    end GetADedIcWarningsProv; 

end; 
/

你會再後來使用此功能,如下所示:

declare 

    table_content tq84_sss.record_t; 

begin 

    table_content := tq84_sss.GetADedIcWarningsProv; 

    for i in 1 .. table_content.count loop 

     dbms_output.put_line(table_content(i).col_1 || ' ' || 
          table_content(i).col_2 || ' ' || 
          table_content(i).col_3 
         ); 

    end loop; 

end; 
/
+3

關鍵的一點強調的是,如果你想`SELECT *`,那麼你應該去clare從表定義派生的記錄類型:`type record_t是tq84_test_table%rowtype;`的表。 – 2011-01-19 13:31:07

0

只使用%ROWTYPE

declare 
... 
someTableRow someTable%rowtype; 
... 
begin 
select * into someTableRow from someTable where blah; 
...