if select count(1) from test3 where id = 2 >0
  select 1 from dual 
else
  select 2 from dual
上面这句话报错,,请问用oracle怎么写的啊?

解决方案 »

  1.   

    if select count(1) from test3 where id = 2 >0;
       select 1 from dual;  
    else
       select 2 from dual;也不能啊if select count(1) from test3 where id = 2 >0
       select 1 from dual;  
    else
       select 2 from dual;‘也不行if ((select count(1) from test3 where id = 2) >0)
       select 1 from dual;  
    else
       select 2 from dual;‘
      

  2.   

    case when select count(1) from test3 where id = 2 >0
     then  select 1 from dual;  
    else
       select 2 from dual;
    也不行啊
      

  3.   

    试试这样写
    DECLARE
      rnt int := 0;
    BEGIN
      SELECT COUNT(1) INTO rnt FROM t_test ;
      
      IF (rnt >0) THEN
        --select 1 from dual;
        dbms_output.put_line('aaaaaaa');
      ELSE
        --select 2 from dual;
        dbms_output.put_line('bbbbbb');
      END IF;
    END;