---
title: "Oracle中trim函数的用法 "
author: "wiseboyloves"
date: "2011-11-03T15:54:00Z"
tags: []
categories: ["数据库"]
slug: "oracle-trim"
draft: false
lastmod: "2011-11-03T15:54:00Z"
id: 1233520
url: "https://wiseboyloves.iteye.com/blog/1233520"
---

trim一般都是用在删除字符串两边的空格。实际上，trim也可以用来删除字符串两边的指定字符。并且trim指定删除的字符串只能是单个字符。如 trim('字符1' from '字符串2') ，字符1只能是单个字符。  
1\. trim()删除字符串两边的空格。  
2\. ltrim()删除字符串左边的空格。  
3\. rtrim()删除字符串右边的空格。  
4\. trim('字符1' from '字符串2')  分别从字符2串的两边开始，删除指定的字符1。  
5\. trim(\[leading | trailing | both] trim\_char from string)　从字符串String中删除指定的字符trim\_char。  
  leading:从字符串的头开始删除。  
  trailing:从字符串的尾部开始删除。  
  borth:从字符串的两边删除。  
6\. tim()只能删除半角空格。 

For example:

trim('   tech   ')  would return 'tech'；

trim(' '  from  '   tech   ')         would return 'tech'；

trim(leading '0' from '000123')      would return '123'；

trim(trailing '1' from 'Tech1') would return 'Tech'；

trim(both '1' from '123Tech111')    would return '23Tech'；