ORA-06502: PL/SQL: 数字或值错误,我贴出来,大家帮我改一下,以前没怎么写过存储过程。。

执行EXEC SQM_RESULT_PRO ;
ORA-06502: PL/SQL: 数字或值错误
ORA-06512: 在"TELEUSER.SQM_RESULT_PRO", line 30
ORA-06512: 在line 2

create or replace procedure SQM_RESULT_PRO is
str varchar2(4096);--最终拼的字符串
str2 varchar2(4096);--最终拼的字符串
ndate varchar2(64); --当天日期
cnum NUMBER(6);--当天的条数
CURSOR resname1 IS select resname from sqm_result_log where restype='1';
CURSOR resname2 IS select resname from sqm_result_log where restype='2';
begin
--开始
select to_char(sysdate,'yyyy-MM-dd') into ndate from dual;
select count(*) into cnum from sqm_result_log where to_char(restime,'yyyy-MM-dd')=ndate;
--判断当天的是否为6个文件
if cnum = 6 then
--系统运行正常
str:='系统运行正常';
else if cnum<6 then
--系统运行不正常
str:='系统运行不正常';
end if;
end if;
--open resname1 for select resname from sqm_result_log where restype='1';
--close resname1;
--open resname2 for select resname from sqm_result_log where restype='2';
--close resname2;
OPEN resname1;
loop
fetch resname1 into str2;
str:=str||' '||str2;
exit when resname1 % NOTFOUND;
end loop;
CLOSE resname1;

str2:='';

OPEN resname2;
loop
fetch resname2 into str2;
str:=str||' '||str2;
exit when resname2 % NOTFOUND;
end loop;
CLOSE resname2;

insert into testsqm values(str);
end SQM_RESULT_PRO;

刚刚看了一下,语法没有太大问题,怀疑是变量长度不够造成的问题。
把str、str2、cnum的长度修改一下,字符串改为32767,这个是最大的长度,number不限定长度,修改如下:
Str VARCHAR2(32767); --最终拼的字符串
Str2 VARCHAR2(32767); --最终拼的字符串
Ndate VARCHAR2(64); --当天日期
Cnum NUMBER; --当天的条数追问

insert into testsqm values(str);

插入的时候这个testsqm 表改成long类型的?改完了然后str没有数据啊。。str查询出来的东西必定是有数据的啊。这个怎么检查呢?用pl/sql

追答

testsqm 表的结构什么样,发出来

追问

..忘记贴了。就这一个字段啊。。测试能不能插进去
create table TESTSQM
(
TEST LONG
)
tablespace USERS
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);

追答

在insert into testsqm values(str); --之后,需要提交,增加
commit;
然后执行过程,执行后查询TESTSQM表中数据就行了。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-12-07
ORA-6502: 数字或值错误,一般出现在将字符串(varchar)类型转换为数值类型失败时候出现
检查下程序中变量和表列的数据类型是否一致
第2个回答  2012-12-12
fetch resname2. resname into str2;