翻译具体描述信息

某个表里面有个字段存的是多个id,中间用逗号隔开的,
比如 这个字段的值为:P00008,P00004,P00006,P00005,P00007
二这种id编号对应的就是一个product产品表
这个产品表的字段有 product_id,productdesc对应关系
P00008,A产品
P00004,B产品
P00006,C产品
P00005,F产品
P00007,Z产品
P00009,G产品
P00003,T产品
可能这个表还有其他产品的id,而且对应的的A表的那个字段也有可能记录其他的id需要显示出来这个字段的内容为
A产品,B产品,C产品,F产品,Z产品
请问如何通过sql实现?

作者: oceantang   发布时间: 2011-06-10

最好能提供oracle的实现方式

作者: oceantang   发布时间: 2011-06-10

建议转去ORACLE板块去问

作者: maco_wang   发布时间: 2011-06-10

MSSQL的处理:
SQL code
create table tb(id varchar(200))
insert into tb select 'P00008,P00004,P00006,P00005,P00007' union all select 'P00009,P00003'
create table product(product_id varchar(10),productdesc nvarchar(10))
insert into product select 'P00008','A产品'
insert into product select 'P00004','B产品'
insert into product select 'P00006','C产品'
insert into product select 'P00005','F产品'
insert into product select 'P00007','Z产品'
insert into product select 'P00009','G产品'
insert into product select 'P00003','T产品'
go
while exists(select 1 from tb a where exists(select 1 from product where charindex(product_id,a.id)>0))
update a set id=replace(a.id,b.product_id,b.productdesc) from tb a inner join product b on charindex(b.product_id,a.id)>0
select * from tb
go
drop table tb,product
/*
id
--------------------------------------
A产品,B产品,C产品,F产品,Z产品
G产品,T产品

(2 行受影响)
*/

作者: qianjin036a   发布时间: 2011-06-10

只能update原来的字段的值嘛?能不能通过select查询出来呢?

作者: oceantang   发布时间: 2011-06-10