Oracle TRIM Function


/ Published in: SQL
Save to your folder(s)

A few examples of the TRIM function.


Copy this code and paste it in your HTML
  1. --Example 1
  2. SELECT TRIM('Jack ') AS trimmed FROM dual;
  3.  
  4. --Example 2
  5. SELECT TRIM(' John') AS trimmed FROM dual;
  6.  
  7. --Example 3
  8. SELECT TRIM(' Julie ') AS trimmed FROM dual;
  9.  
  10. --Example 4
  11. SELECT TRIM(LEADING ' ' FROM ' Julie ') AS trimmed FROM dual;
  12.  
  13. --Example 5
  14. SELECT TRIM(TRAILING ' ' FROM ' Julie ') AS trimmed FROM dual;
  15.  
  16. --Example 6
  17. SELECT TRIM(BOTH ' ' FROM ' Julie ') AS trimmed FROM dual;
  18.  
  19. --Example 7
  20. SELECT TRIM('_' FROM 'Jordan___') AS trimmed FROM dual;
  21.  
  22. --Example 8
  23. SELECT 'first line' || CHR(9) || 'after tab' || CHR(10) || 'next line' || CHR(13) || 'another line' AS FULL_STRING,
  24. TRIM(
  25. TRANSLATE(
  26. TRANSLATE(
  27. TRANSLATE('first line' || CHR(9) || 'after tab' || CHR(10) || 'next line' || CHR(13) || 'another line', CHR(10), ' ')
  28. , CHR(13), ' ')
  29. , CHR(09), ' ')
  30. ) AS trimmed
  31. FROM dual;
  32.  
  33. --Example 9
  34. SELECT first_name
  35. FROM customers
  36. WHERE customer_id = 123;
  37.  
  38. UPDATE customers
  39. SET first_name = TRIM(first_name)
  40. WHERE customer_id = 123;
  41.  
  42. SELECT first_name
  43. FROM customers
  44. WHERE customer_id = 123;

URL: http://www.databasestar.com/oracle-trim/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.