管道行

时间:2016-10-26 12:19:39

标签: sql oracle pipelined-function

我有一个函数返回一个记录列表,然后我循环遍历列表并管道它们,但是在管道中我得到ORA-01403: no data found错误。

下面是我正在使用的代码,我在某些行上收到此错误,而不是所有行。

注意:tab_pipe.t_tabtab.t_tab是同一记录tab.r_tab的表格。

Function pipelinedFunction(ref varchar2, seq varchar2) Return tab_pipe.t_tab pipelined Is
pragma autonomous_transaction;
  errtxt varchar2(400);
  tab tab.t_tab;
begin
  tab := generate_table(ref, seq);

  for i in 1 .. tab.count loop
    begin
      pipe row(tab(i));
    EXCEPTION
      when others then
        v_errtxt := sqlerrm;
        insert into test_kc values('an error occurred piping the row i = ' || i || ' - sqlerrm = ' || v_errtxt); commit;
    end;
  end loop;

  return;
end pipelinedFunction;

1 个答案:

答案 0 :(得分:2)

对于i的每个值,也许选项卡中没有条目。

使用第一个和下一个

尝试循环
declare
  l_index PLS_INTEGER;
BEGIN
  l_index := tab.FIRST;

  WHILE (l_index IS NOT NULL)
  LOOP
    pipe row(tab(l_index)); 
    l_index := tab.NEXT(l_index);
  END LOOP;
END;