select
  a.mcd, a.mnm, a.mknm, a.mnms, a.mknms, a.mzip, a.madd1||' '||a.madd2 madd, a.mtel, a.mfax,
  a.stp, decode(a.stp,null,'inputReadOnly','inputReadOnlyStp') readcolor
from afm04 a
where (:cd is null or a.mcd like '%'||:cd) 		/* 前方一致 */
  and (:nm is null or (upper(comnpack.MultiTOSingleBytesEx(a.mnm))
                                like '%'||upper(comnpack.MultiTOSingleBytesEx(:nm))||'%' or	/* 前後曖昧 */
                         upper(comnpack.MultiTOSingleBytesEx(a.mnms))
                                like '%'||upper(comnpack.MultiTOSingleBytesEx(:nm))||'%' or	/* 前後曖昧 */
                         upper(comnpack.MultiTOSingleBytesEx(a.mknm))
                                like '%'||upper(comnpack.MultiTOSingleBytesEx(:nm))||'%' or	/* 前後曖昧 */
                         upper(comnpack.MultiTOSingleBytesEx(a.mknms))
                                like '%'||upper(comnpack.MultiTOSingleBytesEx(:nm))||'%') )	/* 前後曖昧 */
  and (:zip is null or (upper(comnpack.MultiTOSingleBytesEx(a.mzip))
                                like '%'||upper(comnpack.MultiTOSingleBytesEx(:zip)||'%')) )	/* 前後曖昧 */
  and (:madd is null or (upper(comnpack.MultiTOSingleBytesEx(a.madd1||a.madd2))
                                like '%'||upper(comnpack.MultiTOSingleBytesEx(:madd))||'%' or	/* 前後曖昧 */
                         upper(comnpack.MultiTOSingleBytesEx(a.mkad1||a.mkad2))
                                like '%'||upper(comnpack.MultiTOSingleBytesEx(:madd))||'%') )	/* 前後曖昧 */
  and (:tel is null or (upper(comnpack.MultiTOSingleBytesEx(a.mtel))
                                like '%'||upper(comnpack.MultiTOSingleBytesEx(:tel)||'%')) )	/* 前後曖昧 */
  and (:fax is null or (upper(comnpack.MultiTOSingleBytesEx(a.mfax))
                                like '%'||upper(comnpack.MultiTOSingleBytesEx(:fax)||'%')) )	/* 前後曖昧 */
  and ((NVL(:stpflg, '0') = '1' ) or (NVL(:stpflg, '0') = '0' and a.stp is null))
order by a.mcd
