select tybm_id as tybm,decode(HZHBM_ID ,0,'zcls','否','SHFJC') as jmbh
  from t_fhdjh
  where tybm_id=p_tybm
  and substr(to_char(hzbm_id),1,2)=p_zrcbm
  and HZHBM_ID not in (select jmbh from t_gncz where tybm_id=p_tybm
  and substr(jmbh,1,2)=p_zrcbm
  and nf=p_nf); 

解决方案 »

  1.   

    not in 应该放在WHERE 子句中:
    select tybm_id as tybm,HZHBM_ID as jmbh,0 as zcls,'否' as SHFJC
      from t_fhdjh
      where tybm_id=p_tybm and substr(to_char(hzbm_id),1,2)=p_zrcbm
    and HZHBM_ID not in(select jmbh from t_gncz where tybm_id=p_tybm
      and substr(jmbh,1,2)=p_zrcbm
      and nf=p_nf) ; 
      

  2.   

    select tybm_id as tybm from t_fhdjh where  HZHBM_ID not in(select jmbh from t_gncz where tybm_id=p_tybm
      and substr(jmbh,1,2)=p_zrcbm
      and nf=p_nf) as jmbh and substr(to_char(hzbm_id),1,2)=p_zrcbm;