sql 问题
有这样的数据保存在 picture字段, picture字段类型为NCLOB:Image\酒店\JIUDIAN_RGCJ1\雅悦酒店(北京红庙店)\C_11.jpg,Image\酒店\JIUDIAN_RGCJ1\雅悦酒店(北京红庙店)\C_12.jpgImage\酒店\JIUDIAN_RGCJ1\海悦花园大酒店(长安镇)\C_11.JPG,Image\酒店\JIUDIAN_RGCJ1\海悦花园大酒店(长安镇)\C_12.JPG,Image\酒店\JIUDIAN_RGCJ1\海悦花园大酒店(长安镇)\C_13.JPG,Image\酒店\JIUDIAN_RGCJ1\海悦花园大酒店(长安镇)\C_14.JPG,Image\酒店\JIUDIAN_RGCJ1\海悦花园大酒店(长安镇)\C_15.JPG,Image\酒店\JIUDIAN_RGCJ1\海悦花园大酒店(长安镇)\C_16.JPG用语句:
select poi_id, substr(to_char(picture),instr(picture,'\',1,3+4*(rn-1))+1,instr(picture,'\',1,4+4*(rn-1))-instr(picture,'\',1,3+4*(rn-1))-1)AS picture2  from tb_poi_酒店_rgcj,(SELECT ROWNUM rn FROM DUAL CONNECT BY ROWNUM<=6) where substr(to_char(picture),instr(picture,'\',1,3+4*(rn-1))+1,instr(picture,'\',1,4+4*(rn-1))-instr(picture,'\',1,3+4*(rn-1))-1) is not null截出来是像这样的数据:
POI_ID        PICTURE2
2120000001        三亚喜来登度假酒店
2120000001        三亚喜来登度假酒店
2120000002        西安凯悦酒店
2120000002        西安凯悦酒店
2120000003        北京国际艺苑皇冠假日酒店
2120000004        广州香格里拉大酒店
2120000004        广州香格里拉大酒店
2120000004        广州香格里拉大酒店
2120000004        广州香格里拉大酒店
2120000004        广州香格里拉大酒店
2120000004        广州香格里拉大酒店
2120000005        天津凯悦酒店
2120000008        北京万豪酒店
2120000008        北京万豪酒店
2120000008        北京万豪酒店select poi_id, substr(to_char(picture),instr(picture,'\',1,3+4*(rn-1))+1,instr(picture,'\',1,4+4*(rn-1))-instr(picture,'\',1,3+4*(rn-1))-1)AS picture  from tb_poi_酒店_rgcj,(SELECT ROWNUM rn FROM DUAL CONNECT BY ROWNUM<=6) where substr(to_char(picture),instr(picture,'\',1,3+4*(rn-1))+1,instr(picture,'\',1,4+4*(rn-1))-instr(picture,'\',1,3+4*(rn-1))-1) is not null
group by poi_id, substr(to_char(picture),instr(picture,'\',1,3+4*(rn-1))+1,instr(picture,'\',1,4+4*(rn-1))-instr(picture,'\',1,3+4*(rn-1))-1)
having count(*)>1
然后我想group by ,找出有POI_ID相同的,但PICTURE2有不相同的,但那些截出来完全相同的也查出来了,我想问题应该出在字段类型NCLOB上,如果不能改变字段类型,改怎么解决

解决方案 »

  1.   

    select distinct poi_id, substr(to_char(picture),instr(picture,'\',1,3+4*(rn-1))+1,instr(picture,'\',1,4+4*(rn-1))-instr(picture,'\',1,3+4*(rn-1))-1)AS picture2  from tb_poi_酒店_rgcj,(SELECT ROWNUM rn FROM DUAL CONNECT BY ROWNUM <=6) where substr(to_char(picture),instr(picture,'\',1,3+4*(rn-1))+1,instr(picture,'\',1,4+4*(rn-1))-instr(picture,'\',1,3+4*(rn-1))-1) is not null;直接用distinct不行吗
      

  2.   

    找出有POI_ID相同的,但PICTURE2有不相同的那试试下面这句:with tb as (select distinct poi_id, substr(to_char(picture),instr(picture,'\',1,3+4*(rn-1))+1,instr(picture,'\',1,4+4*(rn-1))-instr(picture,'\',1,3+4*(rn-1))-1)AS picture  from tb_poi_酒店_rgcj,(SELECT ROWNUM rn FROM DUAL CONNECT BY ROWNUM <=6) where substr(to_char(picture),instr(picture,'\',1,3+4*(rn-1))+1,instr(picture,'\',1,4+4*(rn-1))-instr(picture,'\',1,3+4*(rn-1))-1) is not null)
    select * from tb where poi_id in 
    (select poi_id from tb group by poi_id having count(*) > 1);
      

  3.   

    试试这样可以吗我觉得和NCLOB没什么关系。。
      

  4.   

    恩,可以了,想问下为什么用group by 不行了~
      

  5.   


    哪个group by 不行啊???要找出有POI_ID相同的,但PICTURE2有不相同的,那就要对pid_id做group by,然后再统计distinct picture2的数量啊
      

  6.   

    那我 group by poi_id, substr(to_char(picture),instr(picture,'\',1,3+4*(rn-1))+1,instr(picture,'\',1,4+4*(rn-1))-instr(picture,'\',1,3+4*(rn-1))-1) 
    having count(*)>1 
    2120000001        三亚喜来登度假酒店 
    2120000001        三亚喜来登度假酒店这个POI_ID 就不应该出现了吧~
      

  7.   


    当然会出现你的这个group by的意思 正是 查找poi_id和picture2都相同的重复记录,意思正好反了。
      

  8.   

    表a,表b 是同一张表。
    select a.* from table a ,table b where a.poi_id=b.poi_id and a.picture<>b.picture;
    这条SQL达到你的要求。