日期:2014-05-16  浏览次数:20441 次

ORACLE for 循环时报数字溢出异常

??? 今天调试存储过程时遇到个问题,在for循环时报数字溢出异常

?

??? 找了一些资料发现for循环变量的范围只能在-2147483648 , 2147483647之间了;

??? 解决方法:将for循环改为使用WHILE循环即可。

?

The bounds of a loop range can be literals, variables, or expressions but must evaluate
to numbers. Otherwise, PL/SQL raises the predefined exception VALUE_ERROR. The
lower bound need not be 1, but the loop counter increment or decrement must be 1.

j IN -5..5
k IN REVERSE first..last
step IN 0..TRUNC(high/low) * 2

Internally, PL/SQL assigns the values of the bounds to temporary PLS_INTEGER
variables, and, if necessary, rounds the values to the nearest integer. The magnitude
range of a PLS_INTEGER is -2147483648 to 2147483647
, represented in 32 bits. If a
bound evaluates to a number outside that range, you get a numeric overflow error when
PL/SQL attempts the assignment.

?