PL SQL如何选择所有列

发布于 2024-10-12 22:17:36 字数 1013 浏览 2 评论 0原文

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

How do i make the following wrapper select all columns "*" instead of just if_type, and number_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;
/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

山川志 2024-10-19 22:17:36

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

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

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

I am not sure if I do understand your question and requirement.

But if you're looking for a way to get a table's content, or a portion thereof, this is probably how you would approach it:

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

You would then later use this function like so:

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;
/
葬花如无物 2024-10-19 22:17:36

只需使用%rowtype

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

just use %rowtype

declare
...
someTableRow someTable%rowtype;
...
begin
select * into someTableRow from someTable where blah;
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文