有两个手机机型的终端表,tab1里字段device都是机型最精简的机型型号,而tab2 里的字段里除了有机型型号
以外,还有其他的一些字符,现在要求tab1 和tab2关联,使得tab1里精简的型号能够和tab2里的
模糊匹配,测试数据如下:
--tab1的数据
insert into tab1 (SNAME)
values ('R750');insert into tab1 (SNAME)
values ('Phone');insert into tab1 (SNAME)
values ('XT806');insert into tab1 (SNAME)
values ('三星I909');insert into tab1 (SNAME)
values ('T9199');insert into tab1 (SNAME)
values ('N930');--tab2的数据
create table tab2 (device varchar(50);
insert into tab2 (DEVICE)
values ('(代理商)中兴R750(指定智能3G)');insert into tab2 (DEVICE)
values ('联想乐Phone(指定智能3G)');insert into tab2 (DEVICE)
values ('(代理商)摩托罗拉XT806(指定智能3G)');insert into tab2 (DEVICE)
values ('MOTOME811(指定智能3G)');insert into tab2 (DEVICE)
values ('三星I909(指定智能3G)');insert into tab2 (DEVICE)
values ('(代理商)HTC-T9199(指定智能3G)');insert into tab2 (DEVICE)
values ('酷派N930(指定智能3G)');insert into tab2 (DEVICE)
values ('三星W899(指定智能3G)');insert into tab2 (DEVICE)
values ('(代理商)摩托罗拉XT800(指定智能3G)');insert into tab2 (DEVICE)
values ('摩托罗拉XT800(指定智能3G)');insert into tab2 (DEVICE)
values ('摩托罗拉XT800(员工指定智能3G)');insert into tab2 (DEVICE)
values ('(代理商)MOTO-XT800+(指定智能3G)');insert into tab2 (DEVICE)
values ('MOTOXT800+(指定智能3G)');insert into tab2 (DEVICE)
values ('MOTO XT806(指定智能3G)');
以外,还有其他的一些字符,现在要求tab1 和tab2关联,使得tab1里精简的型号能够和tab2里的
模糊匹配,测试数据如下:
--tab1的数据
insert into tab1 (SNAME)
values ('R750');insert into tab1 (SNAME)
values ('Phone');insert into tab1 (SNAME)
values ('XT806');insert into tab1 (SNAME)
values ('三星I909');insert into tab1 (SNAME)
values ('T9199');insert into tab1 (SNAME)
values ('N930');--tab2的数据
create table tab2 (device varchar(50);
insert into tab2 (DEVICE)
values ('(代理商)中兴R750(指定智能3G)');insert into tab2 (DEVICE)
values ('联想乐Phone(指定智能3G)');insert into tab2 (DEVICE)
values ('(代理商)摩托罗拉XT806(指定智能3G)');insert into tab2 (DEVICE)
values ('MOTOME811(指定智能3G)');insert into tab2 (DEVICE)
values ('三星I909(指定智能3G)');insert into tab2 (DEVICE)
values ('(代理商)HTC-T9199(指定智能3G)');insert into tab2 (DEVICE)
values ('酷派N930(指定智能3G)');insert into tab2 (DEVICE)
values ('三星W899(指定智能3G)');insert into tab2 (DEVICE)
values ('(代理商)摩托罗拉XT800(指定智能3G)');insert into tab2 (DEVICE)
values ('摩托罗拉XT800(指定智能3G)');insert into tab2 (DEVICE)
values ('摩托罗拉XT800(员工指定智能3G)');insert into tab2 (DEVICE)
values ('(代理商)MOTO-XT800+(指定智能3G)');insert into tab2 (DEVICE)
values ('MOTOXT800+(指定智能3G)');insert into tab2 (DEVICE)
values ('MOTO XT806(指定智能3G)');
create table tab1 (device varchar(20)) ;
insert into tab1 (SNAME)
values ('R750');insert into tab1 (SNAME)
values ('Phone');insert into tab1 (SNAME)
values ('XT806');insert into tab1 (SNAME)
values ('三星I909');insert into tab1 (SNAME)
values ('T9199');insert into tab1 (SNAME)
values ('N930');
where instr(t2.DEVICE,t1.SNAME)> 0
select t2.*
from tab1 t1,tab2 t2
where instr(t2.DEVICE,t1.SNAME)>0
create table tab1 (sname varchar(20)) ;
select * from tab1;
SNAME
--------------------
R750
Phone
XT806
三星I909
T9199
N930
--
create table tab2 (device varchar(50));
select * from tab2;DEVICE
--------------------------------------------------
(代理商)中兴R750(指定智能3G)
联想乐Phone(指定智能3G)
(代理商)摩托罗拉XT806(指定智能3G)
MOTOME811(指定智能3G)
三星I909(指定智能3G)
(代理商)HTC-T9199(指定智能3G)
酷派N930(指定智能3G)
三星W899(指定智能3G)
(代理商)摩托罗拉XT800(指定智能3G)
摩托罗拉XT800(指定智能3G)
摩托罗拉XT800(员工指定智能3G)
(代理商)MOTO-XT800+(指定智能3G)
MOTOXT800+(指定智能3G)
MOTO XT806(指定智能3G)
--
select t1.sname,t2.device
from tab1 t1,tab2 t2
where instr(t2.device,t1.sname)>0;SNAME DEVICE
-------------------- --------------------------------------------------
R750 (代理商)中兴R750(指定智能3G)
Phone 联想乐Phone(指定智能3G)
XT806 (代理商)摩托罗拉XT806(指定智能3G)
XT806 MOTO XT806(指定智能3G)
三星I909 三星I909(指定智能3G)
T9199 (代理商)HTC-T9199(指定智能3G)
N930 酷派N930(指定智能3G)
--
select *
from tab2
where device like '%R750%' or
device like '%Phone%' or
device like '%XT806%' or
device like '%T9199%' or
device like '%N930%';DEVICE
--------------------------------------------------
(代理商)中兴R750(指定智能3G)
联想乐Phone(指定智能3G)
(代理商)摩托罗拉XT806(指定智能3G)
(代理商)HTC-T9199(指定智能3G)
酷派N930(指定智能3G)
MOTO XT806(指定智能3G)
select t1.sname,t2.device
from tab2 t2,tab1 t1
where regexp_instr(t2.device,t1.sname,1)>0