表A
id  synced
1     1
2     1
3     1
4     1
5     2
我用select synced from test where rownum<6;
能搜出这五条记录,下面我要取到这五条记录的synced字段,并一一对比,在这五条记录里如果有一条是2的话,将做一种处理,如果全是1的话做另一种处理。请问应该怎么写法?感激不尽,只要能达到目地就可

解决方案 »

  1.   

    declare
    ls_synced number(3);
    begin
    with a as
    (select 1 as id , 1 as synced from dual union
    select 2 as id , 1 as synced from dual union
    select 3 as id , 1 as synced from dual union
    select 4 as id , 1 as synced from dual 
    union select 5 as id , 2 as synced from dual
    )
    select distinct(synced) into ls_synced from a 
    where exists (select 1 from dual where synced = 2);if ls_synced = 2 then 
     --操作1
    else 
     --操作2
    end if;
    end;
      

  2.   

    if ls_synced = 2 then  
     --操作1
    else  
     --操作2
    end if;
    end;
      

  3.   

    是想用一条SQL语句搞定
    是想用存储过程搞定
    是想用编程语言搞定
      

  4.   

    select t.*, decode(t.synced ,'1','aa','2','bbb')from test t where rownum<6 order by t.id asc ;select t.*,CASE synced WHEN  '1' THEN  'aa' when  '2' then  'bb' END  from test t where rownum<6 order by t.id asc ;  自己修改一下,不知道可能满足。