Posted By

jgomez on 03/28/12


Tagged

mysql String functions substring


Versions (?)

Find and Replace MySQL column with substring


 / Published in: MySQL
 

Example: There is a table, 'user', with a column, 'clear', containing values such as:

`clear

\'animal\' \'pass'\ `

and we would like to retrieve 'animal' and 'pass' ( without the pre & post \' )

  1. SELECT
  2. TRIM( BOTH '\\\'' FROM clear )
  3. FROM user
  4. WHERE
  5. SUBSTRING( clear, 1, 1 ) = '\\'
  6.  
  7. UPDATE user
  8. SET clear = TRIM( BOTH '\\\'' FROM clear )
  9. WHERE
  10. SUBSTRING( clear, 1, 1 ) = '\\'

Report this snippet  

You need to login to post a comment.