【赵渝强老师】SQL的字符函数

字符函数,顾名思义,操作的就是字符串。通过下图,我们来了解一下Oracle的字符函数。

 

 一、大小写控制函数

  • lower、upper、initcap
select lower('Hello World') 转小写,upper('Hello World') 转大写,initcap('hello world') 首字母大写
from dual;

   

二、字符控制函数

  • substr(a,b) 从a中,第b位开始取

select substr('Hello World',3) from dual;

   

  • substr(a,b,c) 从a中,第b位开始取, 取c位
select substr('Hello World',3,4) from dual;

  

  • length 字符数 lengthb 字节数
--对于英文来说,字符数和字节数一样
select length('Hello World') 字符, lengthb('Hello World') 字节 from dual;

--对于中文来说,一个字符数等于两个字节数
select length('中国') 字符, lengthb('中国') 字节 from dual;

   

  • instr(a,b) 在a中,查找b
select instr('Hello World','ll') 位置 from dual;

 

  • lpad 左填充 ,rpad右填充  
select lpad('abcd',10,'*') 左,rpad('abcd',10,'*') 右 from dual;

   

  • trim 去掉前后指定的字符:去掉前后的‘H’
select trim('H' from 'Hello WorldH') from dual;

   

  • replace替换
select replace('Hello World','l','*') from dual;

  

 

posted @ 2020-04-06 13:29  赵渝强老师  阅读(368)  评论(0编辑  收藏  举报