问题
I have a function written in SQL developer and every time I want to execute I get value or numeric error and I simply cannot get where I have gone wrong.
This is my code so if someone can give me some tips on where my mistake is hidden I would be grateful.
The types that are used in the code are defined and mostly consist of varchar objects and tables of objects and I am properly putting them as an input variable.
I am getting frustrated with that error because I have written similar function already and it was working just fine, but now I have spent 4 hours on trying to figure out where value or numeric error is.
function get_tbank_service_status_bulk (
p_bank_id_tab IN bank_id_tab,
p_service_status_tab OUT bank_service_status_tab
) return ITF_RETURN_REC
is
v_count number;
n_message_id number;
k_out number := 0;
ret_rec ITF_RETURN_REC;
cursor tbstatus_cur (p_bank_id_tab bank_id_tab)
is select tbc.rowid row_id, tbc.BANK_ID bank_id, tbc.service_status service_status
from TABLE (CAST (p_bank_id_tab AS bank_id_tab)) bid, mdm.mdm_tbank_customer tbc where bid.bank_id=tbc.bank_id ;
type cur_tbstatus_tab is table of tbstatus_cur%rowtype;
l_tbstatus_status cur_tbstatus_tab;
BEGIN
select MESSAGE_ID_SEQ.nextval into n_message_id from dual;
v_count := p_bank_id_tab.COUNT;
p_service_status_tab := bank_service_status_tab();
if v_count = 0 then
return itf_return_rec(0, ' ', n_message_id, ' ');
end if;
open tbstatus_cur(p_bank_id_tab);
fetch tbstatus_cur bulk collect into l_tbstatus_status;
for i in l_tbstatus_status.first..l_tbstatus_status.last
loop
if l_tbstatus_status(i).row_id is null then
p_service_status_tab.extend;
k_out := p_service_status_tab.last;
p_service_status_tab(k_out) := bank_service_status_rec(l_tbstatus_status(i).bank_id, -1);
DBMS_OUTPUT.PUT_LINE( 'nes1 || : ' );
else
DBMS_OUTPUT.PUT_LINE( 'nes4 || : ' );
p_service_status_tab.extend;
k_out := p_service_status_tab.last;
p_service_status_tab(k_out) := bank_service_status_rec(l_tbstatus_status(i).bank_id,l_tbstatus_status(i).service_status);
end if;
end loop;
if tbstatus_cur%isopen then
close tbstatus_cur;
end if;
ret_rec := ITF_RETURN_REC(0, ' ', n_message_id, ' ');
commit;
return ret_rec;
exception
when others then
rollback;
if tbstatus_cur%isopen then
close tbstatus_cur;
end if;
ret_rec := ITF_RETURN_REC(-1, 'Error while performing operation!', n_message_id, SQLERRM);
mdm_itf_logger.log_end('ERROR');
return ret_rec;
end get_tbank_service_status_bulk;
回答1:
Add the following to list out where exactly the error is happening.
DBMS_OUTPUT.put_line( SQLERRM || UTL_TCP.crlf || DBMS_UTILITY.format_error_backtrace );
来源:https://stackoverflow.com/questions/57951542/value-or-numeric-error-in-a-function-and-i-cant-detect-where-i-have-gone-wrong