Skip to content
Advertisement

Oracle SQL Error Code ORA-06502: PL/SQL: numeric or value error: character string buffer too small at line 18

I have been stuck trying to fix this error for a while and I cannot figure it out. I have researched this error code and the problem is I am trying to store a number/char that cannot fit into a variable. Everything looks fine within my code and I cannot find the problem.

Here is the Student table information:

Here is the code that I am using:

When I run the code I get this error message:

I am trying to find out whether the student is in or out of Texas. I will add 1 to the in_state or out_state depending on whether the student is in or out of Texas. I will also print a message telling the user the student is in or out of Texas. When the loop is finished, I print the totals of in_state and out_state.

Advertisement

Answer

I think you’re wrong about error position. Should be the next command:

because you declared STU_NAME CHAR; and that’s not enough.

You’d rather declare variables so that they inherit columns’ datatypes, e.g.

Doing so, you’d avoid such problems.


Also, try to avoid CHAR datatype unless values you stored into such a column/variable are fixed length. Because – CHAR right pads values with spaces up to the maximum length of the column so you usually have to truncate it. Pick VARCHAR2 instead.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement