sql 查找字段中某字符的位置

2025-03-04 19:16:20
推荐回答(2个)
回答1:

1、创建测试表,

create table test_student(id number, remark varchar2(20));

2、插入测试数据

insert into test_student values(1001, 1014133);

insert into test_student values(1002, 2014131);

insert into test_student values(1003, 3014132);

insert into test_student values(1004,4010135);

commit;

3、查询表中全量数据,select t.*, rowid from test_student t;

4、编写语句,查询出10这两个数字在remark字段值中的位置;

   select t.*, instr(remark,'10') loc from test_student t ;

   可以发现部分记录并没有10,所以返回值是0;

回答2:

select charindex('10',学号) from 表名

得到的结果就是10的起始位置