Pular para o conteúdo

Fóruns SQL e PL/SQL Execução de procedure que retorna table of record Execução de procedure que retorna table of record

#78315
itiburski
Participante

    Segue um exemplo de manipulação de PL/Tables. Espero que ajude.

    create or replace package PKG_TESTE is

    Type Erro_Type Is Record(
    Cod_Erro Number(03),
    Msg_Erro Varchar2(100));

    Type Lista_Erro_Type Is Table Of Erro_Type Index By Binary_Integer;

    Procedure prc_teste(po_retorno Out Lista_Erro_Type);

    end PKG_TESTE;
    /

    create or replace package body PKG_TESTE is

    Procedure prc_teste(po_retorno Out Lista_Erro_Type) Is
    Begin
    po_retorno(1).cod_erro := 1;
    po_retorno(1).msg_erro := 'mensagem 1';
    po_retorno(2).cod_erro := 2;
    po_retorno(2).msg_erro := 'mensagem 2';
    po_retorno(3).cod_erro := 3;
    po_retorno(3).msg_erro := 'mensagem 3';
    End;

    end PKG_TESTE;
    /

    -- Testando a rotina

    declare
    vs_retorno pkg_teste.Lista_Erro_Type;
    begin
    pkg_teste.prc_teste(vs_retorno);
    for ind in vs_retorno.first..vs_retorno.last loop
    dbms_output.put_line(vs_retorno(ind).cod_erro || ' - ' || vs_retorno(ind).msg_erro);
    end loop;
    end;