How to solve oracle errors such as ora-06502

When we are programming and we get an oracle error, we can capture this error in an exception block. Within this block, we could use the variable sqlerrm in order to know its description.

Here it is an example:

declare
tmp varchar2(10);
begin
tmp:=’aaaaaaaaaaaaaa’;
exception
when others then
dbms_output.put_line(sqlcode||’–>’||sqlerrm);
end;

In this example, we have forced an ora-06502 error and we have captured it with the clause “when others”. We obtain the code with the internal variable sqlcode and we can obtain its description using the internal variable sqlerrm.

I hope you enjoyed it.

:-)

2 Responses

  1. More info of this error here (in spanish): http://www.orasite.com/errores/ORA-06502.html

    ORA-06502 - July 17th, 2008 at 7:16 am
  2. I’m getting this error, but the sqlcode and sqlerrm are not providing any information outside of “-6502: ORA-06502: PL/SQL: numeric or value error”. The error is happening on a fetch statement that looks like this:

    FETCH p_cursor INTO v_rec.param1, v_rec.param2, etc..

    I’ve checked over and over again, and the v_rec matches perfectly the column types that the cursor’s rows contains. There may be some columns in v_rec that are slightly larger in size, but that shouldn’t be a problem when the p_cursor’s columns can’t exceed those sizes. There are also no columns in v_rec that are marked as “not null”. Is there any other way to get more information about this error outside of what you’ve posted here?

    Tom - July 28th, 2008 at 2:42 pm

Leave a Reply