INSTR('City=Amsterdam', '=', -1)
使用 -1 作为开始位置!
根据您的评论,回答 2
select SUBSTR( input, INSTR(input, '=', -1)+1 ) as city
from yourTable;
如果您在之前或之后有更多字段,正如您在 customer=... 中提到的那样,您可以这样做:
select substr(input,
INSTR(input,'City=')+5,
INSTR(input,'"', INSTR(input,'City='))-INSTR(input,'City=')-5
) as city from city;
以及某种“花哨”查询,用于评论并使其与其他字段更加灵活......
select substr(c.input, c.citystart, c.cityend - c.citystart) as city
from (
select input as input,
INSTR(input,'City=')+5 as citystart,
INSTR(input,'"', INSTR(input,'City=')) as cityend
from city) c;
测试数据:
create table city (input char(64));
insert into city values('"City=Amsterdam"; "Customer=124"');
insert into city values('"Customer=11"; "City=USA"');
insert into city values('"Tel=+00"; "City=China"; "Customer=1"');
insert into city values('"Tel=+00"; "Post=11111"; "Customer=333"; "City=Canada"');
查看更新的 SQLFIDDLE: