请各位高人帮忙看看这个存储过程:
create or replace procedure altersamplewatchlog
as
id samplewatchlog.id%type;
samplenumber samplewatchlog.samplenumber%type;
channelno samplewatchlog.channelno%type;
begintime samplewatchlog.begintime%type;
endtime samplewatchlog.endtime%type;
nseconds int;
i int;
begin
i:=0;
declare cursor AAAA is select id,samplenumber,channelno,begintime,endtime from samplewatchlog ;
begin
open AAAA;
loop
fetch AAAA into id,samplenumber,channelno,begintime,endtime;

Exit when  AAAA%NOTFOUND;

select (to_number(ENDTIME-BEGINTIME)*1440) into nseconds from samplewatchlog where id=id; 
if nseconds-(round(nseconds)) > 0 then 
nseconds :=nseconds+1;
else
nseconds :=round(nseconds);
end if;
begin
while i<=nseconds
loop
 insert into samplewatchlogtemp (id,samplenumber,channelNO,begintime,endtime)
 values (sq_testsamplewatchlog.nextval,samplenumber,channelno,begintime,begintime+1/24/60);

i := i+1;
begintime :=begintime+1/24/60;
end loop;
end;
end loop;
close AAAA;
commit;
end;
end altersamplewatchlog;执行时报错: 
ORA-01422: 实际返回的行数超出请求的行数

解决方案 »

  1.   

    select (to_number(ENDTIME-BEGINTIME)*1440) into nseconds from samplewatchlog where id=id; 
    这条记录返回了多条记录
      

  2.   

    up!up!我也认为是你的这条查询语句into nesconds时,是多条记录,所以不匹配。
      

  3.   

    select (to_number(ENDTIME-BEGINTIME)*1440) into nseconds from samplewatchlog where id=id; 
    这个语句中的变量名id与字段名id是同名的,所以会报01422错误。改正方法是将变量id改名,如v_id,再将上面语句改为id=v_id
      

  4.   

    select into的时候需要加入多行或者0行返回的异常保护.
      

  5.   

    先select count(*) into cnt from ...
    判断一下,if cnt<>1 then 异常
    else 继续 ...
      

  6.   

    select (to_number(ENDTIME-BEGINTIME)*1440) into nseconds from samplewatchlog where id=id;
    查询出的数据不止一条,可以自己add debug information调试一下
      

  7.   

    to_number(ENDTIME-BEGINTIME)*1440,因为ENDTIME与BEGINTIME有多个,所以有多条记录
      

  8.   

    如果查出的数据多条相同数据的话 可以加一个 AND rownum = 1select (to_number(ENDTIME-BEGINTIME)*1440) into nseconds from samplewatchlog where id=id   AND rownum = 1
      

  9.   

    楼主要注意bobfang(匆匆过客) 的说法呀。