ITPub博客

首页 > Linux操作系统 > Linux操作系统 > [转]Bug 4458790 ora-06502

[转]Bug 4458790 ora-06502

原创 Linux操作系统 作者:blackdragon0 时间:2007-12-17 13:34:57 0 删除 编辑
Oralce的一些版本,当在函数里执行了min/max操作,并且这个min/MAX的参数是一个char型的字段将出错,这是一个BUG,BUG号Bug 4458790
我测试了win的9.2.0.7没有问题,但是10.2.0.1由问题

SQL
> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL
/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS
for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0
- Production
5 rows selected
.

SQL> create table test(name char(5));
Table created.
SQL> insert into test values('a');
1 row created.
SQL> commit;
Commit complete.
SQL> create  or  replace  function  myf (p in varchar2)  return  char
2 is
3 v_1 char
;
4 begin
5 select min
(nameinto  v_1 from test;
6 return(v_1);
7 end myf;
8 /

Function
created.

SQL> select myf('a'from dual;
select myf('a'from dual

*
ERROR at line 1:
ORA-06502: PL/SQLnumeric  or  value errorcharacter  string  buffer  too  small

ORA
-06512: at "A.MYF", line 5

解决方案
将表字段由char为varchar2型

drop table test
;
create table test(name varchar2(5));
insert  into  test values('A');

SQL> select  myf('a'from  dual;

MYF('A')
---------------------------------
A

1 row selected
.
atgc 发表于:2007.08.30 19:09 ::
 
经过试验和思考,觉得从文章描述的程序来看,不能算是oracle的bug,function中参数v_1是char型,没有制定长度,也就是说实际长度为1,当表的字段类型为char(5)时,要往char(1)的变量中插值,自然会报06502,而表字段类型改成varchar2后,等于说长度为1的值往char(1)中插,自然不会抱错。不知道作者是怎么在win 9207下测的,居然没抱错。2个事实也可以说明这一点:
1)将v_1类型定义为char(5),select语句不抱错
2)表字段类型改为varchar2(5),插入表的值为'aa',select语句一样抱错。

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

上一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2007-12-17

  • 博文量
    4
  • 访问量
    84413