日期:2014-05-17  浏览次数:20868 次

帮我看一个错误“实际返回的行数超出请求的行数”
CREATE OR REPLACE PROCEDURE CHECK_ONEMINUTEINFO_TOTALVOLUM
 (
  s_code sh_origin_stock.stockcode%TYPE,
  t_time2 sh_origin_stock.stockcode%TYPE
  )
IS
  scode stock_shanghai_oneminuteinfo.stockcode%TYPE;
  t_time1 sh_origin_stock.indicationtime%TYPE;
  t_time3 sh_origin_stock.indicationtime%TYPE;
  dvolum sh_origin_stock.dealvolum%TYPE;
  dvolum1 sh_origin_stock.dealvolum%TYPE;
CURSOR cur_tab
IS
  SELECT max(indicationtime) t_time3,max(dealvolum) dvolum
  FROM sh_origin_stock
  WHERE stockcode=NVL(s_code, stockcode) and indicationtime=NVL(to_date(t_time2,'yyyymmdd hh24miss'),indicationtime)
  group by stockcode;

/*
  SELECT time t_time,stockcode scode1,newprice nprice,volum vlum,amount amt,maxprice maxpri,
  minprice minpri,closeprice closepri,openprice openpri,ratio rat
  FROM stock_shanghai_newprice
  WHERE stockcode=NVL(s_code, stockcode) and time=NVL(to_date(t_time2,'yyyymmdd hh24miss'),time);
  -- and stockcode=000001;*/
BEGIN
  FOR each_rec IN cur_tab
  LOOP
  BEGIN
  SELECT distinct stockcode 
  INTO scode
  FROM sh_origin_stock
  WHERE stockcode=NVL(s_code, stockcode) 
  and indicationtime=NVL(to_date(t_time2,'yyyymmdd hh24miss'),indicationtime);
  END;
  BEGIN
  DBMS_OUTPUT.put_line (scode);
  SELECT sum(max(distinct(totalvolum)))
  INTO dvolum1
  FROM stock_shanghai_oneminuteinfo
  WHERE stockcode=scode
  --AND time=NVL(to_date(t_time2,'yyyymmdd hh24miss'),time)
  group by minutecount,stockcode;
  --DBMS_OUTPUT.put_line(each_rec.id_1);
  --DBMS_OUTPUT.put_line('chang'||dvolum1);
  --DBMS_OUTPUT.put_line('feng'||each_rec.dvolum);
  IF dvolum1 is null THEN
  DBMS_OUTPUT.put_line (s_code||','||each_rec.t_time3||','||'Stock_shanghai_oneminuteinfo not found in the table data!');
  ELSE  
  IF dvolum1 <> each_rec.dvolum THEN
  DBMS_OUTPUT.put_line (s_code||','||each_rec.t_time3||','||'Please check the data!');
  ELSE
  DBMS_OUTPUT.put_line (s_code||','||each_rec.t_time3||','||'Data correctly!');
  END IF;
  END IF;
  EXCEPTION
  WHEN TOO_MANY_ROWS THEN
  DBMS_OUTPUT.put_line ('too many rows'); 
  WHEN NO_DATA_FOUND
  THEN
  DBMS_OUTPUT.put_line (s_code||','||each_rec.t_time3||','||'No data found!');
  WHEN OTHERS
  THEN
  DBMS_OUTPUT.PUT_LINE(s_code||','||each_rec.t_time3||','||'Unknown Error!');
  END;
  END LOOP;
END;

error info:

SQL> exec check_oneminuteinfo_totalvolum('','')
BEGIN check_oneminuteinfo_totalvolum('',''); END;

*
第 1 行出现错误:
ORA-01422: 实际返回的行数超出请求的行数
ORA-06512: 在 "XINHUA.CHECK_ONEMINUTEINFO_TOTALVOLUM", line 29
ORA-06512: 在 line 1

------解决方案--------------------
大于1行的话用游标或数组才行
------解决方案--------------------
帮你数到29行的,问