code_junkie

Does the MySQL TRIM function not trim line breaks or carriage returns?

Nov 12th, 2011
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. REPLACE(FIELD,'rn',' ')
  2.  
  3. CREATE FUNCTION `multiTrim`(string varchar(1023),remove varchar(63)) RETURNS varchar(1023) CHARSET utf8
  4. BEGIN
  5. -- Remove trailing chars
  6. WHILE string<>"" and remove like concat('%',substring(string,-1),'%') do
  7. set string = substring(string,1,length(string)-1);
  8. END while;
  9. -- Remove leading chars
  10. while string<>"" and remove like concat('%',left(string,1),'%') do
  11. set string = substring(string,2);
  12. end while;
  13. RETURN string;
  14. END;
  15.  
  16. select multiTrim(string,"rnt ");
  17.  
  18. select trim(BOTH 'n' from [field_name]) as field
  19.  
  20. update [table_name] set [field_name] = trim(BOTH 'n' from [field_name])
  21.  
  22. UPDATE table SET field=REPLACE(field, field, TRIM(BOTH 'rn' FROM field))
  23.  
  24. update events set eventuniqueid = substring(eventuniqueid, 1, 6) where length(eventuniqueid) = 7;
Add Comment
Please, Sign In to add comment