【赵强老师】SQL的字符函数
字符函数,顾名思义,操作的就是字符串。通过下图,我们来了解一下Oracle的字符函数。
一、大小写控制函数lower、upper、initcap12select
lower(
'Hello World'
) 转小写,upper(
'Hello World'
) 转大写,initcap(
'hello world'
) 首字母大写
from dual;
二、字符控制函数
substr(a,b) 从a中,第b位开始取
1select
substr(
'Hello World'
,3) from dual;
substr(a,b,c) 从a中,第b位开始取, 取c位
1select
substr(
'Hello World'
,3,4) from dual;
length 字符数 lengthb 字节数
12345--对于英文来说,字符数和字节数一样
select
length(
'Hello World'
) 字符, lengthb(
'Hello World'
) 字节 from dual;
--对于中文来说,一个字符数等于两个字节数
select
length(
'中国'
) 字符, lengthb(
'中国'
) 字节 from dual;
instr(a,b) 在a中,查找b1
select
instr(
'Hello World'
,
'll'
) 位置 from dual;
lpad 左填充 ,rpad右填充
1select
lpad(
'abcd'
,10,
'*'
) 左,rpad(
'abcd'
,10,
'*'
) 右 from dual;
trim 去掉前后指定的字符:去掉前后的‘H’
1select
trim(
'H'
from
'Hello WorldH'
) from dual;
replace替换
1select
replace(
'Hello World'
,
'l'
,
'*'
) from dual;
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。