ORA-06502:PL/SQL :numberic or value error: character string buffer too small
时间:2022-03-13 23:38
今天遇到一个错误提示:ORA-06502:PL/SQL :numberic or value error: character string buffer too small,一般对应的中文信息为:ORA-06502: PL/SQL: 数字或值错误 :字符串缓冲区太小。仔细检查调试过程中才发现是开发人员定义了一个变量,但是在脚本里面赋予了该变量超过其长度的值。结果就报这个错误。我习惯总结每一个遇到的错误信息,既有利于学习、总结知识,也方便以后遇到此类问题能够及时给出解决方法。
如果执行oerr ora 06502命令,没有提及详细原因(Cause)以及解决方法(Action)。这个估计是出现这类错误的场景太多了的缘故。
$ oerr ora 06502
06502, 00000, "PL/SQL: numeric or value error%s"
// *Cause:
// *Action:
在官方文档http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/datatypes.htm,我看到了关于ORA-06502的错误的一些出现场景。非常有意思。有兴趣的最好直接阅读源文档。
1: 赋值或插入超过长度的值。
Assigning or Inserting Too-Long Values
If the value that you assign to a character variable is longer than the maximum size of the variable, an error occurs. For example:
PLS_INTEGER and its subtypes can be implicitly converted to these data types:
·
· CHAR
·
· VARCHAR2
·
· NUMBER
·
· LONG
All of the preceding data types except LONG, and all PLS_INTEGER subtypes, can be implicitly converted to PLS_INTEGER.
A PLS_INTEGER value can be implicitly converted to a PLS_INTEGER subtype only if the value does not violate a constraint of the subtype. For example, casting the PLS_INTEGER value NULL to the SIMPLE_INTEGER subtype raises an exception, as Example 3-5 shows.
Example 3-5 Violating Constraint of SIMPLE_INTEGER Subtype
3: User-Defined Constrained Subtype Detects Out-of-Range Values
Example 3-7 User-Defined Constrained Subtype Detects Out-of-Range Values
4: Implicit Conversion Between Constrained Subtypes with Same Base Type
A constrained subtype can be implicitly converted to its base type, but the base type can be implicitly converted to the constrained subtype only if the value does not violate a constraint of the subtype (see Example 3-5).
A constrained subtype can be implicitly converted to another constrained subtype with the same base type only if the source value does not violate a constraint of the target subtype.
Example 3-8 Implicit Conversion Between Constrained Subtypes with Same Base Type
5: Implicit Conversion Between Subtypes with Base Types in Same Family
Example 3-9 Implicit Conversion Between Subtypes with Base Types in Same Family
1: DECLARE2:3: SUBTYPE Word IS CHAR(6);4:5: SUBTYPE Text IS VARCHAR2(15);6:7: verb Word := ‘run‘;8:9: sentence1 Text;10:11: sentence2 Text := ‘Hurry!‘;12:13: sentence3 Text := ‘See Tom run.‘;14:15: BEGIN16:17: sentence1 := verb; -- 3-character value, 15-character limit18:19: verb := sentence2; -- 5-character value, 6-character limit20:21: verb := sentence3; -- 12-character value, 6-character limit22:23: END;24:25: /26:27: Result:28:29: DECLARE30:31: *32:33: ERROR at line 1:34:35: ORA-06502: PL/SQL: numeric or value error: character string buffer too small36:37: ORA-06512: at line 1338:39:40:ORA-06502:PL/SQL :numberic or value error: character string buffer too small,布布扣,bubuko.com
热门排行
今日推荐
热门手游