Oracle TRIM函数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle TRIM函数相关的知识,希望对你有一定的参考价值。

A few examples of the TRIM function.
  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;

以上是关于Oracle TRIM函数的主要内容,如果未能解决你的问题,请参考以下文章

oracle中的trim函数

oracle经常使用函数

Oracle TRIM函数

oracle中trim,ltrim,rtrim函数用法

ORACLE sql调优之记录一次trim函数引发的大表全表扫描

trim()函数的用法