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

2022-10-08,,,,

字符函数,顾名思义,操作的就是字符串。通过下图,我们来了解一下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;

  

 

《【赵强老师】SQL的字符函数.doc》

下载本文的Word格式文档,以方便收藏与打印。