select
  a.cucd, a.cunm, a.cuknm, a.cuzip, a.cuad1||a.cuad2 cuad,
  a.cutel, a.cufax,
  a.custp stp, decode(a.custp,null,'inputReadOnly','inputReadOnlyStp') readcolor
from afm03 a
where (:ccd is null or a.cucd like :ccd||'%' or a.cuedi like :ccd)					/* 前方一致 */
  and (:cnm is null or (upper(comnpack.MultiTOSingleBytesEx(a.cunm))
                                like '%'||upper(comnpack.MultiTOSingleBytesEx(:cnm))||'%' or      /* 前後曖昧 */
                         upper(comnpack.MultiTOSingleBytesEx(a.cuknm)) 
                                like '%'||upper(comnpack.MultiTOSingleBytesEx(:cnm))||'%' or      /* 前後曖昧 */
                         upper(comnpack.MultiTOSingleBytesEx(a.cunms))
                                like '%'||upper(comnpack.MultiTOSingleBytesEx(:cnm))||'%' or      /* 前後曖昧 */
                         upper(comnpack.MultiTOSingleBytesEx(a.cuknms)) 
                                like '%'||upper(comnpack.MultiTOSingleBytesEx(:cnm))||'%') )      /* 前後曖昧 */
  and (:zip is null or (upper(comnpack.MultiTOSingleBytesEx(a.cuzip)) 
                                like '%'||upper(comnpack.MultiTOSingleBytesEx(:zip)||'%')) )      /* 前後曖昧 */
  and (:sadd is null or (upper(comnpack.MultiTOSingleBytesEx(a.cuad1||a.cuad2))
                                like '%'||upper(comnpack.MultiTOSingleBytesEx(:sadd))||'%' or     /* 前後曖昧 */
                         upper(comnpack.MultiTOSingleBytesEx(a.cukad1||a.cukad2))
                                like '%'||upper(comnpack.MultiTOSingleBytesEx(:sadd))||'%') )     /* 前後曖昧 */
  and (:tel is null or (upper(comnpack.MultiTOSingleBytesEx(a.cutel))
                                like '%'||upper(comnpack.MultiTOSingleBytesEx(:tel)||'%')) )      /* 前後曖昧 */
  and (:fax is null or (upper(comnpack.MultiTOSingleBytesEx(a.cufax))
                                like '%'||upper(comnpack.MultiTOSingleBytesEx(:fax)||'%')) )      /* 前後曖昧 */
  and ((NVL(:stpflg, '0') = '1' ) or (NVL(:stpflg, '0') = '0' and a.custp is null))
order by a.cucd
