字符函数
字符函数的输入参数为字符类型,其返回值是字符类型或数字类型。
Ascii(x)
该函数用于返回字符x的ascii值
例子:查询字母‘a’ 和‘A’ 的ascii码值
select ascii('a') as a的ascii值,
ascii('A') as A的ascii值
from dual;
结果:
length(x)
返回x字符串的长度
例子:得到helloword的长度
select length('helloworld')
from dual;
结果:
concat(x,y)
拼接函数,把y拼接到x的尾部,最后返回拼接后的结果
示例:把word拼接到hello 的尾部
select concat('hello ','world')
from dual;
结果:
lower(x)
把x中的字母转为小写,返回结果
例子:把HELLo转为小写
select lower('HELLo')
from dual;
结果:
substr(x,start[,end])
该函数返回x中的一个字符串,这个字符串从start开始,还可以为这个字符串指定一个可选的end参数,end表示截取字符的数量。
例子:截取helloworld中的word
select substr('helloworld',6)
from dual;
结果:
当有end参数时:
select substr('helloworld',6,5)
from dual;
在oracle数据库中字符串的开始下标是1,并不像通常变成语言一样,字符串的开始下表是0,这里截取的区间左边是闭的。
instr(x,find_string[,start][,occurrence])
功能:在x中找find_string字符串,然后赶回find_string的位置
select instr('I come from china', 'china')
from dual;
结果:
initcap(x)
功能:把x字符串的首字母转大写
select initcap('hello world')
from dual;
结果:
replace(x,‘target’,‘replace’)
功能:在x字符串中找到target,并用replace进行替换
select replace('I come from china', 'china','beijing')
from dual;
结果: