PL SQL如何选择所有列

时间:2011-01-19 10:41:21

标签: sql database oracle plsql

如何让以下包装选择所有列“*”而不只是if_typenumber_infected

--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;
/

2 个答案:

答案 0 :(得分: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;
/

答案 1 :(得分:0)

只使用%rowtype

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