今天遇到一个错误提示: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:

   1: DECLARE

   2:  

   3: c VARCHAR2(3 CHAR);

   4:  

   5: BEGIN

   6:  

   7: c := 'abc ';

   8:  

   9: END;

  10:  

  11: /

  12:  

  13: Result:

  14:  

  15: DECLARE

  16:  

  17: *

  18:  

  19: ERROR at line 1:

  20:  

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

  22:  

  23: ORA-06512: at line 4

  24:  

2: 违反了SIMPLE_INTEGER Subtype约束

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

   1: DECLARE

   2:  

   3: a SIMPLE_INTEGER := 1;

   4:  

   5: b PLS_INTEGER := NULL;

   6:  

   7: BEGIN

   8:  

   9: a := b;

  10:  

  11: END;

  12:  

  13: /

  14:  

  15: Result:

  16:  

  17: DECLARE

  18:  

  19: *

  20:  

  21: ERROR at line 1:

  22:  

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

  24:  

  25: ORA-06512: at line 5

  26:  

3: User-Defined Constrained Subtype Detects Out-of-Range Values

Example 3-7 User-Defined Constrained Subtype Detects Out-of-Range Values

   1: DECLARE

   2:  

   3: SUBTYPE Balance IS NUMBER(8,2);

   4:  

   5: checking_account Balance;

   6:  

   7: savings_account Balance;

   8:  

   9: BEGIN

  10:  

  11: checking_account := 2000.00;

  12:  

  13: savings_account := 1000000.00;

  14:  

  15: END;

  16:  

  17: /

  18:  

  19: Result:

  20:  

  21: DECLARE

  22:  

  23: *

  24:  

  25: ERROR at line 1:

  26:  

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

  28:  

  29: ORA-06512: at line 9

  30:  

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

   1: DECLARE

   2:  

   3: SUBTYPE Digit IS PLS_INTEGER RANGE 0..9;

   4:  

   5: SUBTYPE Double_digit IS PLS_INTEGER RANGE 10..99;

   6:  

   7: SUBTYPE Under_100 IS PLS_INTEGER RANGE 0..99;

   8:  

   9: d Digit := 4;

  10:  

  11: dd Double_digit := 35;

  12:  

  13: u Under_100;

  14:  

  15: BEGIN

  16:  

  17: u := d; -- Succeeds; Under_100 range includes Digit range

  18:  

  19: u := dd; -- Succeeds; Under_100 range includes Double_digit range

  20:  

  21: dd := d; -- Raises error; Double_digit range does not include Digit range

  22:  

  23: END;

  24:  

  25: /

  26:  

  27: Result:

  28:  

  29: DECLARE

  30:  

  31: *

  32:  

  33: ERROR at line 1:

  34:  

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

  36:  

  37: ORA-06512: at line 12

  38:  

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: DECLARE

   2:  

   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: BEGIN

  16:  

  17: sentence1 := verb; -- 3-character value, 15-character limit

  18:  

  19: verb := sentence2; -- 5-character value, 6-character limit

  20:  

  21: verb := sentence3; -- 12-character value, 6-character limit

  22:  

  23: END;

  24:  

  25: /

  26:  

  27: Result:

  28:  

  29: DECLARE

  30:  

  31: *

  32:  

  33: ERROR at line 1:

  34:  

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

  36:  

  37: ORA-06512: at line 13

  38:  

  39:  

  40:  

ORA-06502:PL/SQL :numberic or value error: character string buffer too small的更多相关文章

  1. PL/SQL: numeric or value error: character to number conversion error

    在最简单的plsql块编程中出现这个错误,是因为 DBMS_OUTPUT.PUT_LINE('the x is '+x);这里面不能用“+”,而是要用“||” DECLARE x number; ; ...

  2. PL/SQL异常处理

    As we all known,程序的错误一般分为两类:编译错误和运行时错误.其中运行时错误被称为异常.PL/SQL语句块中处理异常的部分即为异常处理部分.在异常处理部分,可以指定当特定异常发生时所采 ...

  3. PL/SQL EXCEPTION捕获抛出异常

    EXCEPTION抛出异常 处理除数为零异常 declare varA number; begin varA:=10/0; dbms_output.put_line('IT WILL NOT WORK ...

  4. 全面对比T-SQL与PL/SQL

    1)数据类型 TSQL PL/SQL numeric(p,s) numeric(p,s) or NUMBER(p,s) decimal(p,s) decimal(p,s) or NUMBER(p,s) ...

  5. ddl in PL/SQL

    If you write DDL directly in PL/SQL. You will hit error. 1 DECLARE 2 str_sql varchar2(500); 3 begin ...

  6. Oracle 的PL/SQL语言使用

    --PL/SQL语言(procedure language 过程化语言) --1.声明类型 declare k number; m ; --Character String buffer too sm ...

  7. PL/SQL 用户自定义子类型

    子类型具有与其基本类型相同的操作,但只有基本类型有效值的子集. 例如,PL/SQL预先定义子类型CHARACTER和INTEGER,如下所示: SUBTYPE CHARACTER IS CHAR; S ...

  8. PL/SQL Developer 与tnsnames.ora

    PL/SQL Developer 是一款流行的oracle开发与管理的IDE. 在登录PL/SQL Developer时所选择的数据库依赖于tnsnames.ora文件中的信息. 如果我们安装了多个o ...

  9. PLSQL Developer概念学习系列之登录连接Oracle时出现(没有登录) -PL / SQL Developer:ORA - 12541: TNS :无建听程序的错误解决办法(图文详解)

    不多说,直接上干货! 前期博客 PLSQL Developer概念学习系列之如何正确登录连接上Oracle(图文详解)   如用scott.scott_password进行登录,orcl是全局数据库 ...

随机推荐

  1. C# 将excel表格嵌入到Word中

    C# 将excel表格嵌入到Word中 继续开扒,今天要实现的是使用C#将excel表格嵌入到Word中这个功能,将word表格导入到excel中我已经写过了,如有需要可参考我之前的文章,在开始前还有 ...

  2. wcf DataTable作为返回类型

    如果这个DataTable是自己定义的,则再声明DataTable dt=new DataTable("exampleName")时,一定要调用带有一个参数的DataTable个构 ...

  3. H2 数据库

    最近做演示项目的时候需要一个数据库,但不想安装.于是查看了embedded datasource : h2 h2: 依赖: <dependency> <groupId>com. ...

  4. IIS与ASP.NET管道

    IIS 5.x与ASP.NET 我们先来看看IIS 5.x是如何处理基于ASP.NET资源(比如.aspx,.asmx等)请求的,整个过程基本上可以通过图1体现. IIS 5.x运行在进程InetIn ...

  5. jquery技巧之让任何组件都支持类似DOM的事件管理

    本文介绍一个jquery的小技巧,能让任意组件对象都能支持类似DOM的事件管理,也就是说除了派发事件,添加或删除事件监听器,还能支持事件冒泡,阻止事件默认行为等等.在jquery的帮助下,使用这个方法 ...

  6. Rafy 领域实体框架演示(2) - 新功能展示

    本文的演示需要先完成上一篇文章中的演示:<Rafy 领域实体框架示例(1) - 转换传统三层应用程序>.在完成改造传统的三层系统之后,本文将讲解使用 Rafy 实体框架后带来的一些常用功能 ...

  7. jQuery弹出深色系层菜单

    低调奢华jQuery弹出层菜单,使用新版的jQuery库,兼容多种浏览器.Demo展示: http://hovertree.com/texiao/layer/3/ 本特效可以作为网站的引导页,使用jQ ...

  8. 学习笔记(二)——MVC扩展(渲染视图)

    如何渲染视图? 我以近乎的视图引擎为例总结了一下,近乎中的ThemedViewEngine类,就是重写后的的视图引擎.ThemedViewEngine类主要对FindPartialView和FindV ...

  9. webapi修改tt模板给字段添加JsonIgnore特性解决转换json循环引用问题

    0.问题描述 EF生成的model带有导航属性,则json序列化会报循环引用错误,尝试如下 protected void Application_Start() { GlobalConfigurati ...

  10. div悬浮

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...