【问题标题】:PL SQL how to select all columnsPL SQL如何选择所有列
【发布时间】:2011-01-19 10:41:21
【问题描述】:

如何使以下包装器选择所有列“*”而不仅仅是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;
/

【问题讨论】:

    标签: sql database oracle plsql


    【解决方案1】:

    我不确定我是否理解您的问题和要求。

    但是,如果您正在寻找一种获取表格内容或其中一部分内容的方法,您可能会采用以下方法:

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

    【讨论】:

    • 重点要强调的是,如果你想SELECT *,那么你应该声明你的记录类型是从表定义派生的:type record_t is table of tq84_test_table%rowtype;
    【解决方案2】:

    只需使用 %rowtype

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-06
      • 2021-11-29
      • 1970-01-01
      • 2011-10-22
      • 2020-05-08
      • 2016-05-21
      • 2016-06-27
      • 2019-02-02
      相关资源
      最近更新 更多