一对多这种方式该‘1,2,3’该怎么关联

liujin9012 2013-07-02 05:03:22
司机表
车辆表,一台车对应多个司机,这种方式该怎么实现关联,谢谢
...全文
145 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
sych888 2013-07-02
正则表达式regexp_like
回复
hh7yx 2013-07-02
select 司机表.* ,车辆表.* from 车辆表,司机表 where regexp_like(车辆表.driver_id,司机表.driver_id)
回复
sasacat 2013-07-02
select 司机表.* ,车辆表.* from 车辆表,司机表 where instr(车辆表.driver_id,司机表.driver_id)>0
回复
luoyoumou 2013-07-02
create table tb_drivers(
driver_id int,
driver_name varchar2(30 char)
);

INSERT INTO tb_drivers(driver_id,driver_name) values(348,'12345');
INSERT INTO tb_drivers(driver_id,driver_name) values(352,'小三');
INSERT INTO tb_drivers(driver_id,driver_name) values(355,'易特');
INSERT INTO tb_drivers(driver_id,driver_name) values(360,'李大荣');
INSERT INTO tb_drivers(driver_id,driver_name) values(432,'张三');
INSERT INTO tb_drivers(driver_id,driver_name) values(431,'李四');
INSERT INTO tb_drivers(driver_id,driver_name) values(430,'王五');
INSERT INTO tb_drivers(driver_id,driver_name) values(429,'赵六');
INSERT INTO tb_drivers(driver_id,driver_name) values(428,'王麻子');
INSERT INTO tb_drivers(driver_id,driver_name) values(391,'葛二蛋');

COMMIT;


create table tb_buses(
vid int,
driver_id VARCHAR2(100 CHAR)
);

INSERT INTO tb_buses(vid,driver_id) values(102,'432,431,430,429,428');
INSERT INTO tb_buses(vid,driver_id) values(542,'391');
commit;


col driver_ids for a40;
col driver_name for a30;
select t2.vid, t2.driver_id as driver_ids, t1.driver_id, t1.driver_name
from tb_drivers t1 join tb_buses t2 on instr(t2.driver_id||',',to_char(t1.driver_id)||',')>=1;
回复
相关推荐
发帖
Oracle
创建于2007-09-28

1.6w+

社区成员

Oracle开发相关技术讨论
申请成为版主
帖子事件
创建了帖子
2013-07-02 05:03
社区公告
暂无公告