Where is a record that creates an error

It might be that you see one record in a view that generates an error somewhere but you have not clue which record might generate that error. It could then be that the next logic helps. Create this procedure:

create or replace package mypkg_tom
as
cursor c is select * from tpl_v_calc_dossier;
type cur_tab is table of c%rowtype;
function foo return mypkg_tom.cur_tab pipelined;
end;

which is followed by the package definition:

create or replace package body mypkg_tom
as
function foo return mypkg_tom.cur_tab pipelined
as
l_data cur_tab;
begin
open c;
fetch c bulk collect into l_data;
close c;
dbms_output.put_line('omvang '||l_data.count);
for i in 1..l_data.count
loop
pipe row( l_data(i) );
if mod(i, 1000) < 1 then dbms_output.put_line('regel '||i); end if;
if (i between 250000 and 250010) then dbms_output.put_line(i); end if;
end loop;
return ;
end;
end;

It can then be called by something like select count(*) from table( mypkg_tom.foo ); This then shows a counter at each 1000th record. You then know where the error may lie. Next step is to precisely locate the error and solve the issue.

An alternative is to show the ids from the view:

create or replace package mypkg_tom
as
cursor c_varchar is select id from tpl_v_calc_dossier;
type cur_varchar is table of varchar(216);
function foo_varchar return mypkg_tom.cur_varchar pipelined;
end;

followed by

create or replace package body mypkg_tom
as
function foo_varchar return mypkg_tom.cur_varchar pipelined
as
l_data cur_varchar;
opvang varchar(216);
begin
open c_varchar;
fetch c_varchar bulk collect into l_data;
close c_varchar;
dbms_output.put_line('omvang '||l_data.count);
for i in 1..l_data.count
loop
pipe row( l_data(i) );
if mod(i, 1000) < 1 then dbms_output.put_line('regel '||i); end if;
opvang := l_data(i);
if (i between 250000 and 250010) then dbms_output.put_line(opvang); end if;
end loop;
return ;
end;
end;

which can then be called as select count(*) from table( mypkg_tom.foo_varchar );

Door tom