select *
from i11
where p01='{nps04}'
   && p02 like '{peg_str}%'
   && length(p02) in (10, 14)
   && (   length(p02)=10 
      ||  (     substr(p02, 11, 1)='-'
            &&  cast(substr(p02, 12, 3) as signed)<>0 )
      )

order by length(p02) desc;