ORA-01422:精确提取返回超过请求的行数ORA-06512:在第34行

时间:2015-10-27 13:48:47

标签: oracle plsql

对于这个特定的块,我不断得到

  

ora 0142:精确提取返回超过请求的行数

,我尝试过不同的,排名和rownum,但似乎没有任何效果。

begin 
  for i in c1 loop
    if i.estacao_a2 is not null then
      begin
        select migrationidentifier
          into v_master_location
          from (
                    select com.migrationidentifier
                         , row_number () over (partition by com.migrationidentifier order by com.migrationidentifier asc) RK
                      from com_location com
                     where round (i.latitude_a_decimal, 1) =
                            round (com.LATITUDEWGS84, 1)
                       and round (i.longitude_a_decimal, 1) =
                            round (com.longitudewgs84, 1)
                       and com.sourcedomain = 'FENIX'
               )
         where rk=1
             ;
      exception
        when no_data_found
          then dbms_output.put_line ( 'NO RECORDS FOUND IN COM_LOCATION FOR LATITUDE:' || i.latitude_a_decimal);
      end;
    end if;
  end loop;
end;

1 个答案:

答案 0 :(得分:0)

好的,因此com_location中有多个migrationidentifier,用于该组latitude_a_decimal和longitude_a_decimal。这是不好的数据吗?还是可能的?或者有一些排序标准将决定你应该采取哪一个?

如果有订购标准 - 将其添加到您的查询中,然后将查询放入游标并执行OPEN ... FETCH INTO ... CLOSE首先获取该行并填充您的变量。你不需要你的EXCEPTION块以这种方式执行它,而是在获取之后执行IF cursorname%NOTFOUND THEN dbms_output()ENDIF;

declare
  cursor get_migrationidentifier (in_lat_decimal number, in_long_decimal number)
  IS
         select migrationidentifier  from 
         (select com.migrationidentifier
           ,row_number () over (partition by com.migrationidentifier order by com.migrationidentifier asc) RK
           from com_location com
          where round (i.latitude_a_decimal, 1) =
                   round (com.LATITUDEWGS84, 1)
                and round (i.longitude_a_decimal, 1) =
                       round (com.longitudewgs84, 1)
                and com.sourcedomain = 'FENIX') where rk=1
              order by migrationidentifier  ;
begin 
  for i in c1
   loop 
   if i.estacao_a2 is not null then
      OPEN get_migrationidentifier (i.latitude_a_decimal. i.longitude_a_decimal); 
      FETCH get_migrationidentifier  INTO v_master_location;
      IF get_migrationidentifier%NOTFOUND 
      THEN  v_master_location := null;
            dbms_output.
            put_line (
               'NO RECORDS FOUND IN COM_LOCATION FOR LATITUDE:'
               || i.latitude_a_decimal);
      end IF;
      CLOSE get_migrationidentifier;

  end if;
   end loop;