没有记录 怎么into呢,如果是多条 那就是多对1,怎么into呢,你先count一下 然后和1作比较

解决方案 »

  1.   

    begin
    select a.id
       into v_id
       from test a
      where a.id = '100'
     excption when NO_DATA_FOUND then
          --没有找到数据
    when TOO_MANY_ROWS then
         --找到多条数据
    end;
      

  2.   

    begin
      select count(a.id) to is_exists
        from test a
       where a.id = '100';
       
       if IS_EXISTS = 1
       THEN
          select a.id  into v_id
          from test a
          where a.id = '100';
       else
          
       end if;
     end; 
      

  3.   

    You may check the record number first.select count(*) into v_count from test a where a.id =100;
    If the v_count ...
    else...
    end if.
      

  4.   

    返回数据多的话,可以考虑游标cusor
      

  5.   

    用异常捕获来处理。
    如果是要一行一行的处理的话,先将结果select到collect集合中再做处理。
      

  6.   

    SQL> declare v_null varchar2(100) :='ttt';
      2  begin
      3  dbms_output.put_line('v_null:'||v_null);
      4  select null into v_null from dual;
      5  if v_null is null then
      6  dbms_output.put_line('hello world');
      7  end if;
      8  end;
      9  /
    v_null:ttt
    hello worldPL/SQL 过程已成功完成。
      

  7.   

    针对你的情况可以做如下处理SQL> select * from t;NN
    ---------------------------------------------------------
    ---------------------------------------------------------
    ---------------------------------------------------------
    100
    100SQL> declare v_nn varchar2(100);
      2  begin
      3  select distinct nn into v_nn from t where nn='100';
      4  dbms_output.put_line('v_nn='||v_nn);
      5  end;
      6  /
    v_nn=100