Qracle学习:字符串相关函数

(1)lower : 小写, upper :大写,initcap :单词的首字母大写

select lower('HELLO WORLD') "小写", upper('Hello world') "大写", initcap('hello world') "首字母大写" from dual;

(2) concat ( 连接符|| )

select concat('hello ','world') from dual;

注意:concat 函数只能连接两个字符串,若想连接三个的话只能嵌套调用

 select concat(concat('hello ','world'), ' nihao') from dual;
 select 'hello ' || 'world ' || 'nihao' from dual;// || 可以连接多个字符串, 建议使用||来连接字符串

(3)substr(str, pos, len) 截取字符串

select substr('helloworld',1,3), substr('helloworld',1), substr('helloworld',-3) from dual;//pos 是从 1 开始的,若 len 为 0 表示从 pos 开始, 截取到最后,若 pos 为负数,表示从末尾倒数开始截取 

(4) instr(str, substr):判断 substr 是否在 str 中存在,

select instr('hello llo', 'llo'), instr('hello llo', 'ow')from dual;//若存在返回第一次出现的位置,若不存在则返回 0

(5)lpad 和 rpad
返回 len 长度的字符串,如果 str 不够 len 的话,在左(右)填充 ch 这个字符

select lpad('aaaa', 10, '$'), rpad('aaaa', 10, '#') from dual;

(5)trim:去掉首部和尾部的空格;中间的空格不去掉

select 'aaa'||trim(' hello world ')||'bbb' from dual;
 

(6)trim(c from str):去掉 str 中的 c 字符

 select trim('x' from 'xxxxxhello worldxxxxx') from dual;

(7) replace(str, old, new):将 str 字符串中的 old 字符串替换成 new 字符串

 select replace('hello world','llo','yy') from dual;

(8)length 和 lengthb

 select length('hello world') 字符数, lengthb('hello world') 字节数 from dual;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值