ITPub博客

首页 > Linux操作系统 > Linux操作系统 > BUG MAX/MIN INTO CHAR

BUG MAX/MIN INTO CHAR

原创 Linux操作系统 作者:gaopengtttt 时间:2010-07-21 15:14:52 0 删除 编辑

 

(原创 转载请注明出处)

这个BUG出现会报错如下:

select to_char(max(RENEWAL_DATE)) into M_YEAR_MONTH from t_renewal_schedule;

ORA-06502: PL/SQL: 数字或值错误 :  字符串缓冲区太小

这个时候有3个方法可以解决

1、setting initialisation parameter BLANK_TRIMMING=TRUE

2、declare PL/SQL CHAR and VARCHAR2 variable used in the INTO clause of SELECT statement as 4,000 bytes.

3、Use CAST SQL function to constraint the size to that of the variable size like

 SELECT CAST(MIN('Y') AS CHAR(1)) INTO C FROM DUAL;

CAST是强制转换函数。

参数BLANK_TRIMMING 设置为TRUE的时候可以解决我们的BUG问题,同时这个参数设置为TRUE会在进行变量的赋值的时候忽略末尾的空格,同时这个参数必须关闭数据库进行更改。所以请评估下,是否可行。

 

试验如下:

 

SQL> CREATE TABLE abc (

  2  cont_no char(8),

  3  plan_id char(7));

 

Table created

SQL> INSERT INTO abc VALUES ('123456  ', '7654321');   ---(这里空格有2位)

1 row inserted

SQL> commit;

 

SQL> DECLARE

  2     c_Plan_ID char(6);

  3  BEGIN

  4     SELECT cont_no INTO c_Plan_ID from abc;

  5     dbms_output.put_line(c_Plan_ID);

  6  END;

  7  /

DECLARE

   c_Plan_ID char(6);

BEGIN

   SELECT cont_no INTO c_Plan_ID from abc;

   dbms_output.put_line(c_Plan_ID);

END;

ORA-06502: PL/SQL: 数字或值错误 :  字符串缓冲区太小

ORA-06512: 在 line 5

然后我们修改参数BLANK_TRIMMING为true

alter system set BLANK_TRIMMING=true scope=spfile;

重启数据库进行测试

进行测试

SQL>  DECLARE

  2         c_Plan_ID char(6);

  3      BEGIN

  4         SELECT cont_no INTO c_Plan_ID from abc;

  5         dbms_output.put_line(c_Plan_ID);

  6      END;

  7  /

 

123456

 

PL/SQL procedure successfully completed

看到可以完成了

 

下面是METALINK的原话

SELECT containing a MIN or MAX into a CHAR variable inside a PL/SQL block Fails With ORA-06502 [ID 311653.1]  

Applies to:

Oracle Server - Enterprise Edition - Version: 10.1.0.4 to 10.1.0.4

Oracle Server - Enterprise Edition - Version: 9.2.0.6 to 9.2.0.7

Oracle Server - Enterprise Edition - Version: 10.2.0.1 to 10.2.0.1

This problem can occur on any platform.

 

Symptoms

SELECT containing a MIN or MAX into a CHAR variable inside a PL/SQL block Fails With:

 

 

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

 

Example:

 DECLAREC CHAR(1);BEGINSELECT MIN('Y') INTO C FROM dual;END;/DECLARE*ERROR at line 1:ORA-06502: PL/SQL: numeric or value error: character string buffer too smallORA-06512: at line 4Changes

After upgrading to Oracle10gR2 10.2.0.1

After applying 10.1.0.4 patchset

After applying 9.2.0.6 patchset

After applying 9.2.0.7 patchset

Cause

This problem has been identified as

 

Bug:4458790 ORA-6502 selecting MAX/MIN into a CHAR variable in PLSQL

 

This problem is introduced in Oracle9i 9.2.0.6, Oracle10g 10.1.0.4 and 10.2.0.1 by the fix for Bug:3499258.

 

A PLSQL block which SELECTs a MAX or MIN into a fixed CHAR variable can fail with an unexpected ORA-6502 "character string buffer too small" error.

Solution

This problem is fixed in

 

Oracle9iR2 (9.2.0.8, terminal patchset)

Oracle11gR1(11.1.0.x or higher)

Oracle10gR1(10.1.0.5 or higher)

 

Oracle10gR2 (10.2.0.2 or higher)

 

Workarounds:

 

setting initialisation parameter BLANK_TRIMMING=TRUE

 

 

declare PL/SQL CHAR and VARCHAR2 variable used in the INTO clause of SELECT statement as 4,000 bytes.

 

 

Use CAST SQL function to constraint the size to that of the variable size like

 

SELECT CAST(MIN('Y') AS CHAR(1)) INTO C FROM DUAL;

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/7728585/viewspace-668605/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: ORA-04021
下一篇: ORACLE event和说明
请登录后发表评论 登录
全部评论
wxh gp_22389860 公众号 MySQL学习 书籍 深入理解MySQL主从原理

注册时间:2021-06-07

  • 博文量
    868
  • 访问量
    3495548