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

游标求助。
SQL code

 declare
      N    number;
      far_lat varchar2(32);
      far_lon varchar2(32);
      cursor c_CI is select distinct CI from CICENTER;
      c_row c_CI%rowtype;
    begin
      for c_row in c_CI 
        loop
          select round(count(CI)*0.8) into N from CDL_ZX_20120315 where CI=c_row.CI and wso_sn=3 and (access_lat is not null or access_lon is not null);
          select access_lat into far_lat from tmp_access_latlon where CI=c_row.CI and n=N;
          select access_lon into far_lon from tmp_access_latlon where CI=c_row.CI and n=N;
          DBMS_OUTPUT.put_line(c_row.CI||'--'||N||'--'||far_lat||'--'||far_lon);
        END LOOP;
    end;


错误代码:
ORA-01422:exact fetch returns more than requested number of rows
ORA-06512:at line 14

请高人帮看看这是什么原因出现的这个错误。谢谢

------解决方案--------------------
select into
查询出了多条数据,所有出错……采用max() min() sum() avg() 等等函数可以解决
具体根据自己的需求
------解决方案--------------------
select access_lat,access_lon from tmp_access_latlon a where a.CI=c_row.CI and a.n=N1;
这里的查询应该用Into子句放到变量里去。