刚刚表达错了,不好意思,重新问一下,呵呵,我是想实现如果select 有结果(一个,多个均可),我将执行一段代码,如果select 没有结果执行另外的代码,问题是我不知道怎么写这个判断有无的语句,我写了if sql%found then 不好用(我的数据库中有符合条件的记录,可是没有执行if sql%found then 下面的代码),我该怎么写啊???

解决方案 »

  1.   


    begin
       .....
    begin
        select .. into ... from table;
        --以下写有数据时的操作
        ..........
    exception 
        when no_data_found then
           --以下写没有数据时的操作
        ..........
    end; 
       ......
    end;
      

  2.   

    可以使用游标,当cur_name里面的记录为空时,退出procedureexit when cur_name%NOTFOUND;
      

  3.   

    使用游标和record类型declare
    cursor cur is select ....from table;
    record table%rowtype;
    begin
    loop
    fetch cur into record;
    exitwhen cur%notfound;
    ....
    end loop;
    exception
    when no_data_found then
    ....
    end;
      

  4.   

    select count(*) into i from tablename
    if i>0 then
      ....
      --有数据
    else
     ....
    end if;
      

  5.   

    iCount number(10);
    select count(*) into iCOunt form tablename where your conditions;if iCOunt=0 then 
      not find data
    else
    end if;
      

  6.   

    方法有几种
    不过
    plsql中when no_data_found 异常不用定义。
      

  7.   

    Exception虽然能够实现,但是不优雅。或许exists谓词更适合。只有真正出了Exception才用异常处理是好的编程习惯
      

  8.   

    用CURSOR,但可以直接判断
    if cur%notfound then 
    .....
    else
    ....
    end if;
      

  9.   

    用select count(*) into :a  from tableif a=0 then这样 也可以
      方法应该很多