oracle经常使用字符串函数

1.把字符所有转换为大写:upper sql

select ename,upper(ename) upper from emp;

2.把字符所有转换为小写:loweroracle

select ename,lower(ename) lower from emp;

3.把字符串首字母转化为大写:initcap(这个函数只会把首字母转换为大写,若是一个字符串全部字符都是大写,他只会把首字母转换为大写,其他字符都会转换小写,转换形式以下所示:SMITH——>Smith)函数

select ename,initcap(ename) initcap from emp;

4.获取字符串长度:lengthspa

1.select ename,length(ename) length from emp;
2.select length('asdf') from dual;

5.字符串替换:replace(字符串,原始字符串,要替换的字符串) code

1.select ename,replace(ename,'s','_') replace from emp;
2.select replace('hello','e','a') from dual

6.字符串截取:substr(字符串,开始,结束)(注:下标从1开始,但写0oracle也会处理为1,程序从1开始,负数从后面开始截)字符串

select ename,substr(ename,1,4) substr from emp;
select substr('hello','-4','4') from dual;

7.去空格:trim(注:只能去掉字符串两边的空格,夹杂字符串中间的空格去不掉,下面的示例1能够取,示例2取不掉)it

1.select trim('   hello  ') from dual;
2.select trim('h ell o') from dual;
相关文章
相关标签/搜索