oracle中常用的字符函数

字符函数

字符函数的输入参数为字符类型,其返回值是字符类型或数字类型。

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;

结果:

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值