【问题标题】:ORA-01422: exact fetch returns more than requested number of rows ORA-06512: at line 34ORA-01422:精确提取返回的行数超过了请求的行数 ORA-06512:在第 34 行
【发布时间】:2015-10-27 22:05:08
【问题描述】:

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

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

,我尝试过 distinct、rank 和 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;

【问题讨论】:

  • 你把distinct关键字放在哪里了?
  • 这只是意味着您有多个用于 where 子句中的 latitude_a_decimal 和 longitude_a_decimal 值的 migrationidentifier 值。
  • 嗨,collapser,我之前使用过下面提到的查询,但得到相同的错误 select distinct com.migrationidentifier into v_master_location 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';
  • 嗨迈克尔如果我运行查询,我会得到想要的结果。在我在这里运行的脚本中同样不起作用。
  • 在该循环中的某处必须有一个值组合会引发错误。捕获 too_many_rows 异常并输出值以查看它们是什么。

标签: oracle plsql


【解决方案1】:

好的,因此您在 com_location 中有多个针对 latitude_a_decimal 和 longitude_a_decimal 的迁移标识符。这是坏数据吗?还是可能?或者有一些订购标准可以决定您应该选择哪一个?

如果有排序标准 - 将其添加到您的查询中,然后将查询放入游标并执行 OPEN...FETCH INTO ... CLOSE 以首先获取该行并填充您的变量。您不需要 EXCEPTION 块这样做,而是在 fetch 之后执行 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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-15
    • 2021-06-14
    • 2015-09-24
    • 1970-01-01
    相关资源
    最近更新 更多