SOLVED

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

Asked by OracleDba10 viewsoracle

#oracle#error

Solutions(1)

Accepted Solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
ORA-06502: PL/SQL: numeric or value errorstring

Cause:

An arithmetic, numeric, string, conversion, or constraint error occurred. For example, this error occurs if an attempt is made to assign the value NULL to a variable declared NOT NULL, or if an attempt is made to assign an integer larger than 99 to a variable declared NUMBER(2).

Action:

Change the data, how it is manipulated, or how it is declared so that values do not violate constraints.

ORA-06502 exception occurs when arithmetic, numeric, string, conversion, or constraint error occurred. In my views, ORA-06502 normally occurs because of programming bugs and programmer ignorance.

ORA-06502 exception raises by the Oracle Database when:

- We try to assign a larger value a variable can hold

- We try to assign a string to a number type variable

- We try to assign NULL to variable declared as NOT NULL

Examples:

SQL> declare

  2     n number(2);

  3  begin

  4     n := 123;

  5  end;

  6  /

declare

*

ERROR at line 1:

ORA-06502: PL/SQL: numeric or value error: number precision too large

ORA-06512: at line 4

SQL> declare

  2     n number(2);

  3  begin

  4     n := 'test';

  5  end;

  6  /

declare

*

ERROR at line 1:

ORA-06502: PL/SQL: numeric or value error: character to number conversion error

ORA-06512: at line 4

SQL> declare

  2     str varchar2(3);

  3  begin

  4     str := 'test';

  5  end;

  6  /

declare

*

ERROR at line 1:

ORA-06502: PL/SQL: numeric or value error: character string buffer too small

ORA-06512: at line 4

SQL> declare

  2     n1 number not null := 1;

  3     n2 number;

  4  begin

  5     n1 := n2;

  6  end;

  7  /

declare

*

ERROR at line 1:

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

ORA-06512: at line 5
OracleDba

Post Your Solution