title: db2 remove all non-alphanumeric, including non-printable, and special characters
body: <p>This may sound like a duplicate, but existing solutions does not work.
  I need to remove all non-alphanumerics from a varchar field. I'm using the following but it doesn't work in all cases (it works with diamond questionmark characters):</p>
  
  <pre><code>  select TRANSLATE(FIELDNAME, '?',
                   TRANSLATE(FIELDNAME , '', 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')) 
     from TABLENAME
  </code></pre>
  
  <p>What it's doing is the inner translate parse all non-alphanumeric characters, then the outer translate replace them all with a '?'. This seems to work for replacement character�. However, it throws <code>The second, third or fourth argument of the TRANSLATE scalar function is incorrect.</code> which is expected according to IBM:</p>
  
  <p><code>The TRANSLATE scalar function does not allow replacement of a character by another character which is encoded using a different number of bytes. The second and third arguments of the TRANSLATE scalar function must end with correctly formed characters</code>.</p>
  
  <p>Is there anyway to get around this?</p>
  
  <p>Edit: @Paul Vernon's solution seems to be working:</p>
  
  <pre><code>· 6005308      ??6005308
  –6009908       ?6009908
  –6011177       ?6011177
  ��6011183�� ??6011183??
  </code></pre>