oracle如何实现lastindexof的功能

第一种实现方法:reverse(substr(reverse(str),1,INSTR(reverse(str),'_') - 1))利用reverse函数,该函数的功能是反转倒置。但是据测试在存储过程中不能使用。于是到网上找了另外一种实现方法。

第二种:substr(str,instr(str,'_',-1,1)+1,length(str));这种实现没那么难懂了。利用了instr函数求得instr(str,'_',-1,1)求得最后一个‘_’的位置(开始位置)所以我们在用substr截取的时候要加1。instr语法:

instr(string1,string2[,start_position[,nth_appearence]])

string1:要在此字符串中查找。

string2:要在string1中查找的字符串。

start_position:从string1开始查找的位置。可选,默认为1,正数时,从左到右检索,负数时,从右到左检索。

nth_appearence:查找第几次出现string2。可选,默认为1,不能为负。

我们这里第三个参数为-1即从右边查找。正好就是最后一个'_'的开始位置。

ps:insrtr可以实现类似like的功能和in的功能(效率问题没有研究)

select name  from table  where instr(name, 'xx') > 0;等同于select name from table where name like '%xx%';

select name from table where instr('xx,xxx,xxxx',name)>0; 等同于 select name from table where name in('xx','xxx','xxxx');


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值