oracle中查找一个字符串中某个字符的位置是什么函数

2025-02-25 09:59:29
推荐回答(4个)
回答1:

查找位置的函数为instr函数。下标以1开始,如果不存在则返回0。

举例如下:

1、创建测试表,

create table test_instr(str varchar2(20));

2、插入测试数据

insert into test_instr values ('abc');

insert into test_instr values ('cdaf');

insert into test_instr values ('bbed');

3、查询表的记录,select t.*, rowid from test_instr t;

4、编写sql,查找字母'a'在表中各记录的位置;

select t.*, instr(str,'a') location from test_instr t,可以发现,最后一条记录,不存在该字符的话,则返回0。

回答2:

instr函数为字符查找函数,其功能是查找一个字符串在另一个字符串中首次出现的位置。instr函数在Oracle/PLSQL中是返回要截取的字符串在源字符串中的位置。

int index= instr(“abcd”, 'c');
index=

扩展资料:

注意

位置索引号从1开始。

如果String2在String1中没有找到,instr函数返回0。

示例:

SELECT instr('syranmo','s') FROM dual; -- 返回 1

SELECT instr('syranmo','ra') FROM dual; -- 返回 3

SELECT instr('syran mo','at',1,2) FROM dual; -- 返回 0。

参考资料来源:百度百科-instr函数

回答3:

在oracle查找一个字符串中某个字符位置用instr函数。

如以下语句:

select instr('abcdefg','f') from dual;

此句是查f在abcdefg这个字符串中的位置,查询结果:

回答4:

int index= instr(“abcd”, 'c');
index=2