Home oracle Why is the error ORA-06502: number or value error - at run...

Why is the error ORA-06502: number or value error – at run time, not compile time?

Author

Date

Category

Why is the error not caught during compilation, but only occurs during the execution of the procedure? Where is the logic? Or is it a necessity?

create or replace procedure tt is
  a varchar2 (10): = '-6502 - ORA-06502: PL / SQL:: character string buffer too small number or value error';
begin
  null;
end;
begin tt; end;

Answer 1, authority 100%

It will be difficult to give an objective answer to this question, because off. the PL / SQL documentation does not contain a detailed description of the compiler.


Apparently, the question is expected to behave like in other languages, for example:

$ echo "int main () {char a [1] = {'a', 0};}" | gcc -c -o a.o -x c -
& lt; stdin & gt ;: In function ‘main’:
& lt; stdin & gt;: 1: 30: warning: excess elements in array initializer
& lt; stdin & gt;: 1: 30: note: (near initialization for ‘a’)

But in this case, if you ignore the warning, a memory leak will occur.
In the case:

create or replace procedure checkchr is
  val varchar2 (1): = 'ab';
begin null; end;
/

violation of any boundaries or limits will not occur.

Declaration with constraint (1..maxsize) will create a variable with so called constrained data type . Max. the data length (for the VARCHAR2 type is 32767 bytes) for this variable will not change.
The restriction serves to protect against logical errors that may appear during program execution. As you know, it makes no sense to check for logical errors during compilation.

When trying to initialize, where the set limit for the data type will actually be exceeded, compilation of course will fail with an error:

create or replace procedure checknum is
  num number: = 10e999;
begin null; end;
/

Error (51,24): PLS-00569: numeric overflow or underflow

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions