【发布时间】:2011-11-08 14:39:15
【问题描述】:
我有以下函数,我从同一个 pl/sql 包中的另一个过程调用。
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;
当我调用该函数时,它会产生以下错误:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
产生错误是因为变量 v_where_clause 对于我试图存储在变量中的某些字符串来说不够大。我不明白的是,当错误发生时,上面显示的两个异常子句中的任何一个都不会捕获它。而是在调用此函数的过程的异常块上捕获错误。
我知道它没有被函数中的异常子句捕获的原因是两个异常子句都应该将错误条件记录到文件中,但它们不是。
这有什么原因吗? 'WHEN OTHERS' 异常块不应该捕获异常吗?
另外,有什么方法可以在不指定大小的情况下声明 v_where_clause 变量?
谢谢
【问题讨论】:
-
将您的 VARCHAR2 变量指定为非常大的大小,即 32767,Oracle 会自动为其提供足够的存储空间来覆盖您放入的内容。不会随意预留32767字节。
标签: sql oracle plsql oracle10g