ORA 06502 Error PL/SQL

oracle, oracle11g, plsql, sql

Solution

It is due the Operator Precedence.

Multiplication has higher precedence than concatenation. So, `'Addition: '||4*2` evaluates to `'Addition: '||8` and to `'Addition: 8'`.

Addition has same precedence as concatenation and operators with equal precedence are evaluated from left to right. So, `'Addition: '||4+2` evaluates to `'Addition: 4' + 2`, which subsequently fails as you cannot add number to characters.

In such cases, you should always use brackets to explicitly specify the order of evaluation, like this `'Addition: '|| (4+2)`

Problem

I am trying to execute a simple statement and i got an error while executing. ``` begin dbms_output.put_line('Addition: '||4+2); end; ``` Error: ORA-06502: PL/SQL: numeric or value error: character to number conversion error ORA-06512: at line 2 But when i executed with * operator, it worked fine. ``` begin dbms_output.put_line('Addition: '||4*2); end; ``` Does anyone know the reason behind it?

Original source