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

oracle中PL/SQL集合里exists方法的使用。
为什么我用PL/SQL集合里的exists()方法时一直返回是false啊,从来没返回真。
declare
  type eno_table_type is table of emp.empno%type index by binary_integer;
  eno_table eno_table_type;
 begin
  select empno bulk collect into eno_table from emp;
  if eno_table.exists(7788) then
  dbms_output.put_line('数据正确');
  else
  dbms_output.put_line('数据不正确');
  end if;
 end;
上面一直输出‘数据不正确’。但7788确实是emp表里的一个编号,试了其他的数也不行,一直返回假,没有一次是真。
这是怎么回事啊?期待详解…………

------解决方案--------------------
你查询出来的数据有7788条吗?如果没有就显示"数据部正确",这里的7788是说明你查询的结果是否有第7788条,如果你查询结果是10000条,那么这是数据就会显示"数据正确"
------解决方案--------------------
SQL code

declare
  i: Integer;
begin
  select Count(1) 
    into i
    from dual
   where Exists (select 1  
                   from emp
                  where empno = 7788);
  if i = 0 then
    dbms_output.put_line('数据不正确'); 
  else
    dbms_output.put_line('数据正确');
  end if;
end;