the syntax is not working in oracle , but oracle has some other way to do it :

select count(*) 
into  li_count
from user where id = 3;
if li_count > 0 then

do something;
else 
do other things;
end if;

解决方案 »

  1.   

    Or you can do it more tricky:
    Just one sql:-) select * from user where id = 3
     and not exists ( select * from user where id = 4)
    Union
     select * from user where id = 4;
      

  2.   

    也可以这样:
    begin
    select * from user where id=3 
    -- 存在,do something
    exception
    when no_data_found then
    --不存在,do something
      

  3.   

    在Oracle中,EXISTS函数不能用作IF语句的判别条件,EXISTS只能在 SQL 语句中使用
      

  4.   

    可能语法要做修改,但是原理不变,oracle同样可以实现。
      

  5.   

    black_snail的第二种方法没问题的,很有想法的一句sql。但第一句我是这样写的
    select count(*) into  li_count
    from user_dict where id = 3;
    if li_count > 0 then
    select * from user_dict where id=3;
    else 
    select * from user_dict where id=4;
    end if;
    但在sql worksheet中执行出错,
    总是说我“ORA-00900: 无效 SQL 语句”
    不知是不是我写错了
    请指教!
      

  6.   

    给你一个例子思考:
    SQL> declare
      2  num number;
      3  begin
      4  select count(*) into num from aa where rownum<=1;
      5  if sql%notfound then
      6  dbms_output.put_line('没有');
      7  else
      8  dbms_output.put_line('有');
      9  end if;
     10  end;
     11  /
      

  7.   

    if li_count > 0 then
    select * from user_dict where id=3;
    else 
    select * from user_dict where id=4;
    end if;
    有问题,你必须用into 把值取出来.
      

  8.   

    SQL> declare
      2  num number;
      3  begin
      4  select count(*) into num from aa where 1=2;
      5  if num>0 then
      6  dbms_output.put_line('没有');
      7  else
      8  dbms_output.put_line('有');
      9  end if;
     10  end;
     11  /
    有0>0根本不能判断,0不能大于0,iv
      

  9.   

    to beckhambobo(beckham) :
    SQL> declare
      2  num number;
      3  begin
      4  select count(*) into num from aa where 1=2;
      5  if num>0 then
      6  dbms_output.put_line('没有');
      7  else
      8  dbms_output.put_line('有');
      9  end if;
     10  end;
     11  /
    有what's the problem , because num = 0 , so if condition failed 
    and system go to else condition and output '有'??????please use >0 anyway , it's safe anyway:-)