I have the following function which i call from another procedure within the same pl/sql package.
Function lf_get_query(p_table in varchar2) return varchar2
Is
v_where_clause varchar2(500);
Begin
Case upper(p_table)
When 'TABLEA' then
v_where_clause := ' Where trunc(x.purchase_dtm) < ' || '''' || trunc(v_check_Date) || '''';
When 'TABLEB' then
v_where_clause := ' Where trunc(x.purchase_dtm) < ' || '''' || trunc(v_check_Date) || ''''
|| ' And product_type='ABC'
|| ' And customer_type='XXX'
|| ' And contract_type='YYY';
Else
raise ex_unknown_table_type;
End case;
return v_where_clause;
Exception
When ex_unknown_table_type then
[[Log to file that table is urecognised. ]]
raise;
When others then
[[Log to file that table is urecognised and include sqlerrm ]]
raise;
End;
When i call the function, it generates the following error:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
The error is generated because the variable v_where_clause is not large enough for some of the strings i am trying to store in the variable. What i don't understand is when the error occurs, it is not caught by any of the two exception clauses shown above. Instead the error is being caught on the exception block for the procedure that is calling this function.
The reason i know it is not being caught by the exception clauses in the function is that both exception clauses are supposed to log the error condition to a file but they are not.
Is there any reason for this? Shouldn't the exception be caught by the 'WHEN OTHERS' exception block?
Also, is there any way i can declare the v_where_clause variable without specifying a size?
Thanks