在oracle中,可用trim()函数来去掉前后的空格,当该函数的参数设置为both时,就会去除指定的首部和尾部字符,语法为“select trim(both ' ' from 字段) as strTemp from tableName”。
本教程操作环境:Windows10系统、Oracle 11g版、Dell G3电脑。
oracle怎么去掉前后的空格
在oracle中,trim()函数的用法有,leading 开头字符,trailing 结尾字符,both 开头和结尾字符,如下:
trim(leading || trailing || both '将要被替换掉的字符" from “将要被替换的字符串")
1、trim函数去除指定的开头字符
select trim(leading 'x' from 'xday') as strTemp from tableName ;
2、trim函数去除指定的结尾字符
select trim(trailing 'x' from 'dayx') as strTemp from tableName ;
3、trim函数去除指定的首部和尾部字符
select trim(both 'x' from 'xdayx') as strTemp from tableName ;
4、默认情况下,trim函数会去除首部和尾部,被指定的字符
select trim('x' from 'xdayx') as strTemp from tableName ;
5、如果没有指定被移除的字符,则会默认去除首部和尾部的空格
select trim(' day ') as strTemp from tableName ;
扩展知识:
语法描述如下:
TRIM([ { { LEADING | TRAILING | BOTH } [ trim_character ] | trim_character } FROM ] trim_source )
参数解释:
leading 开头字符
trailing 结尾字符
both 开头和结尾字符
trim_character 去除的字符
trim_source 修剪源
推荐教程:《Oracle视频教程》