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请高人帮看看这是什么原因出现的这个错误。谢谢

解决方案 »

  1.   

    select  into
    查询出了多条数据,所有出错……采用max() min() sum() avg() 等等函数可以解决
    具体根据自己的需求
      

  2.   


        declare
          v_CI number;
          n1    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
               DBMS_OUTPUT.put_line(c_row.CI);
              select round(count(CI)*0.8) into N1 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);
               DBMS_OUTPUT.put_line(N1);
              select access_lat,access_lon from tmp_access_latlon a where a.CI=c_row.CI and a.n=N1;      END LOOP;    end;数据我一条一条的查询了。没有多啊。那上面的句子 报错:
    ORA-06550:line 16,column 11;
    PLS-00428:an INTO clause is expected in this SELECT statement
    这又是什么原因?
      

  3.   

    select access_lat,access_lon from tmp_access_latlon a where a.CI=c_row.CI and a.n=N1;
    这里的查询应该用Into子句放到变量里去。
      

  4.   

    人家都告诉你了少INTO关键字:
    select access_lat,access_lon from tmp_access_latlon a where a.CI=c_row.CI and a.n=N1;
    这句,from前面得加上INTO啊:
    select access_lat,access_lon INTO 变量1, 变量2 ....
      

  5.   


    我不插入变量 进行查询不可以么? into 变量1,变量2又回到上面的问题了。
      

  6.   

    过程中不能只有纯粹的select语句……具体为什么,我也不知道^-^你游标一条条遍历,不等于 select access_lat from tmp_access_latlon where CI=c_row.CI and n=N;
    查出来就一条啊……
      

  7.   

    结贴。最开始的语句跑通了。不知道什么原因莫名其妙。呵呵。 select access_lat from tmp_access_latlon where CI=c_row.CI and n=N;c_row.CI 和N值 我打印出来了。然后一个一个的输入集体值运行了查询语句没有出现2条记录的情况