获取指定子字符串所在的位置:instr(字段a,子字符串)函数

语法是:INSTR (string , substring [, position [, occurrence ] ])
INSTR函数可以得到子字符串(当然包含单个字符)在字符串中的位置,返回的是数字。
1)得到字母“o”在FIRST_NAME字段第一次出现的位置
sec@ora10g> select FIRST_NAME, instr(FIRST_NAME,‘o’) instr from t;

FIRST_NAME INSTR

Secooler 4

2)从字符串的第5个字符开始查找,第一次出现字母“o”的位置
sec@ora10g> select FIRST_NAME, instr(FIRST_NAME,‘o’,5) instr from t;

FIRST_NAME INSTR

Secooler 5

3)从字符串的第1个字符开始查找,第二次出现字母“o”的位置
sec@ora10g> select FIRST_NAME, instr(FIRST_NAME,‘o’,1,2) instr from t;

FIRST_NAME INSTR

Secooler 5

你可能感兴趣的:(数据库)