首页 » ORACLE 9i-23c » sql 计算字符从后向前出现的位置

sql 计算字符从后向前出现的位置

sql 计算字符从后向前出现的位置,用两个函数,instr,reverse(空格也算一位)

INSTR方法的格式为
INSTR(源字符串, 目标字符串, 起始位置, 匹配序号)

默认查找顺序为从左到右。当起始位置为负数的时候,从右边开始查找。但是下标值还是从前向后的只是如果字符偏后效率快些

sql>select instr(‘abcdefg’,’b’,-1,1) from dual;

2

REVERSE字符串反转函数:

REVERSE(character_expression )

select REVERSE(‘abcdefg’) from dual;

—-

gfedcba

现在说怎么计算从后向前出现的下标值

实验开始

select instr(REVERSE(‘abcdefg’),’f’) from dual;

—–

2

那么

select instr(REVERSE(‘abcdefg’),’f’,-1,1) from dual;

??是多少呢,回复吧

打赏

目前这篇文章有2条评论(Rss)评论关闭。

  1. Bryon Hober | #1
    2011-12-21 at 07:11

    Any person several opportune pieces, it comes surely, as well as you bring in crave of various the many other types of hikers close to you with hard part your question. pre owned awnings

  2. Caro | #2
    2011-06-23 at 09:30

    I ralely needed to find this info, thank God!