去掉首尾空格
SELECT TRIM(' abc '), ltrim(' abc '), rtrim(' abc ') FROM dual;
去掉首尾的其他字符
SELECT /*TRIM(';a;b;c;'),*/ ltrim(';a;b;c;',';'), rtrim(';a;b;c;',';') FROM dual;
注意:無法使用TRIM(‘;a;b;c;’, ‘;’)的格式 但是TRIM()卻有它自己的格式 SELECT TRIM(';' FROM ';a;b;c;'), TRIM(leading ';' FROM ';a;b;c;'), TRIM(trailing ';' FROM ';a;b;c;'), TRIM(both ';' FROM ';a;b;c;') FROM dual;
去掉首尾多個字符
對於去除首尾多個字符的時候,需要特別注意的是,Oracle數據庫會從字符串中掃描,移除掉去除集合中出現的每一個字符,直到遇到第一個不在去除集合中的字符為止,而不是去去掉去除集合中的字符串。
SELECT LTRIM('thetomsbthhe', 'the'),RTRIM('thetomsbthhe', 'the') FROM dual;
注意:TRIM(leading 'the' FROM 'thetomsbthhe')是不行的,此函數的截取集僅能包含一個字符。
select * from ( --租用-- select rownum as 編號,gxrxm as 承租人 ,(case trim(gxrxb ) when '1' then '男' when '2' then '女' else '不詳' end ) as 性別, rtrim( mobilephone ||','|| LXDH, ',') as 聯系方式 , (select (select gxmc from gxxx where t2. gx= gxdm and rownum= 1) from wrxxb t2 where t1.djh=djh and rownum=1 and rq=(select min( rq) from wrxxb where t1. djh= djh)) 關系 ,rq as 辦理日期 ,'租用' as 業務類型 --,mwje as 墓價,zmj 成交價,(mwje-zmj) as 優惠金額 ,(SELECT mj FROM mwdmxx WHERE djh=T1.djh) as 面積 from ywdjb t1 where to_char(rq ,'yyyy-mm-dd')>= '2015-07-01' and to_char(rq, 'yyyy-mm-dd')<='2015-07-31' and zxflag= '0' union all --續租-- select rownum as 編號,t2.gxrxm as 承租人 ,(case trim(t2 .gxrxb ) when '1' then '男' when '2' then '女' else '不詳' end ) as 性別,rtrim( t2.mobilephone|| ','||t2.LXDH,',' ) as 聯系方式 , (select (select gxmc from gxxx where t3 .gx =gxdm and rownum=1) from wrxxb t3 where t1.djh=djh and rownum=1 and rq=(select min( rq) from wrxxb where t1. djh= djh)) 關系 ,t1.rq as 辦理日期 ,t1 .ywmc as 業務類型 from qtywb t1 ,ywdjb t2 where t1 .djh =t2 .djh and to_char(t1. rq, 'yyyy-mm-dd')>='2015-07-01' and to_char(t1.rq,'yyyy-mm-dd' )<='2015-07-31' and t1 .zxflag ='0' and t1.ywmc= '續租' union all --合葬-- select rownum as 編號,t2.gxrxm as 承租人 ,(case trim(t2 .gxrxb ) when '1' then '男' when '2' then '女' else '不詳' end ) as 性別,rtrim( t2.mobilephone|| ','||t2.LXDH,',' ) as 聯系方式 , (select (select gxmc from gxxx where t3 .gx =gxdm and rownum=1) from wrxxb t3 where t1.djh=djh and rownum=1 and rq=(select min( rq) from wrxxb where t1. djh= djh)) 關系 ,t1.rq as 辦理日期 ,t1 .ywmc as 業務類型 from qtywb t1 ,ywdjb t2 where t1 .djh =t2 .djh and to_char(t1. rq, 'yyyy-mm-dd')>='2015-07-01' and to_char(t1.rq,'yyyy-mm-dd' )<='2015-07-31' and t1 .zxflag ='0' and t1.ywmc= '合葬' union all --老墓改造-- select rownum as 編號,t2.gxrxm as 承租人 ,(case trim(t2 .gxrxb ) when '1' then '男' when '2' then '女' else '不詳' end ) as 性別,rtrim( t2.mobilephone|| ','||t2.LXDH,',' ) as 聯系方式 , (select (select gxmc from gxxx where t3 .gx =gxdm and rownum=1) from wrxxb t3 where t1.djh=djh and rownum=1 and rq=(select min( rq) from wrxxb where t1. djh= djh)) 關系 ,t1.rq as 辦理日期 ,t1 .ywmc as 業務類型 from qtywb t1 ,ywdjb t2 where t1 .djh =t2 .djh and to_char(t1 .rq ,'yyyy-mm-dd')>= '2015-07-01' and to_char(t1.rq,'yyyy-mm-dd' )<='2015-07-31' and t1 .zxflag ='0' and t1.ywmc= '老墓改造' ) order by 辦理日期