I'm wondering if there is a way to get a little more information about what caused the exception:
Error starting at line 5 in command:
exec ....
Error report:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at ..., line 558
ORA-06512: at ..., line 752
ORA-06512: at line 1
06502. 00000 - "PL/SQL: numeric or value error%s"
*Cause:
*Action:
I'm assuming this means I have a variable that is too small for what I tried to put in it... But why can't Oracle tell me what variable this is? It would be great for both debugging and production support people to be able to say to our client I think you have this field too big and that's what caused the error, rather than just "some value was too big and we really have no idea which one"... Using the line number would required someone who understood sql and looking at the code which is not ideal.
Why is there nothing under the Cause and Action fields?
When you try to insert into a col with data that is too large it tells you what col... I would like similar information here.
Is that possible without having to put an exception handler after every plsql line of code?
Oracle can't know what your intent is with the error information. Knowing the variable name you're storing it as or where exactly it came from isn't necessarily in the best interests of the end user or security.
For example, I can generate your error easily:
The error already gives the line number.
Would you prefer the error give the variable name (
v_tooshort
)? That's not helpful to a user.Is the right information the value, "too long"? Or the fact that it's a dummy column from the
dual
table? (or an actual column and table)?Because the error arises from a
select into
instead of aninsert
statement, it's not like there's a specific database constraint the exception can identify by name.EDIT (to address issue raised in a comment): That's not true. You'll get the column name and lengths returned when doing an
insert
(as an ORA-12899), but not when doing aselect into
even if it's using data from a table:EDIT 2:
You can nest your
select into
into its own begin-exception-end block and raise whatever error you like (providing a unique error number and descriptive error text):