Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3321126
  • 博文数量: 631
  • 博客积分: 10716
  • 博客等级: 上将
  • 技术积分: 8397
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-01 22:35
文章分类

全部博文(631)

文章存档

2020年(2)

2019年(22)

2018年(4)

2017年(37)

2016年(22)

2015年(1)

2013年(12)

2012年(20)

2011年(19)

2010年(20)

2009年(282)

2008年(190)

分类: Oracle

2008-12-29 14:45:19

对于instr函数,我们经常这样使用:从一个字符串中查找指定子串的位置。例如:
SQL> select instr('yuechaotianyuechao','ao') position from dual;
 
  POSITION
----------
         6
 
从字符串'yuechaotianyuechao'的第一个位置开始,向后查找第一个出现子串'ao'出现的位置。
 
其实instr共有4个参数,格式为“instr(string, substring, position, occurrence)”。可实现子串的如下搜索:
1.从指定位置开始搜索子串
2.指定搜索第几次出现的子串的位置
3.从后向前搜索
 
--1.从第7个字符开始搜索
SQL> select instr('yuechaotianyuechao','ao', 7) position from dual;
 
  POSITION
----------
        17
 
--2.从第1个字符开始,搜索第2次出现子串的位置
SQL> select instr('yuechaotianyuechao','ao', 1, 2) position from dual;
 
  POSITION
----------
        17

--3.从倒数第1个字符开始,搜索第1次出现子串的位置
SQL> select instr('yuechaotianyuechao','ao', -1, 1) position from dual;
 
  POSITION
----------
        17
 
--3.从倒数第1个字符开始,搜索第2次出现子串的位置
SQL> select instr('yuechaotianyuechao','ao', -1, 2) position from dual;
 
  POSITION
----------
         6
阅读(1496) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~