Oracle errors

ORA-06502: PL/SQL: numeric or value error

ORA-06502: PL/SQL: numeric or value error

A PL/SQL assignment or conversion failed: most often a string is longer than the variable can hold (character string buffer too small), a text cannot become a number, or NULL went into a NOT NULL variable.

What it means

ORA-06502 is PL/SQL’s general error for values that do not fit. The text after the colon tells you which kind: character string buffer too small, character to number conversion error, number precision too large or NULL index table key value. The ORA-06512 lines that follow show the exact line of code.

Common causes

How to fix it

  1. Read the ORA-06512 line numbers to find the statement.
  2. Declare variables from the column type: l_name employees.name%TYPE.
  3. Use character length semantics for text that may contain multi-byte characters: VARCHAR2(100 CHAR).
  4. Validate or convert input before assigning it.

Example

Size the variable from the column:

DECLARE
  l_name employees.last_name%TYPE;   -- not VARCHAR2(20)
BEGIN
  SELECT last_name INTO l_name FROM employees WHERE id = 1;
END;

In SQLlightspeed

When a statement fails, SQLlightspeed’s error panel shows the error code with a plain-language explanation and a suggestion for what to do next, together with Oracle’s own message and a link to Oracle’s documentation — for this error and dozens of other common ones.

Related errors

ORA-12899ORA-01722ORA-01403 All Oracle errors →

Oracle documentation for ORA-06502. Oracle is a registered trademark of Oracle Corporation. SQLlightspeed is not affiliated with Oracle.