orcle 10g不支持对类型为CLOB的字段进行distinct去重,遇到这种查询需求时就需要对sql进行修改,以下是几种修改的方法:
1、利用to_char(column)函数将CLOB字段转换为char类型,但是有限制,如果clob字段的字符长度超过4000时会报错。如果必须使用的话建议设置长度,使用 TO_CHAR(SUBSTR(column,0,3999))组合函数
2、使用子查询过滤掉重复数据,然后作为条件参与查询
select d.*, i.Process_Instance_Id from bz_notam_detail d left join bz_notam_info i on d.NOTAM_INFO_ID = i.id where d.PRSSD_NOTAM_PK in (
select distinct e.PRSSD_NOTAM_PK from bz_notam_d_section s left join bz_notam_detail e on s.NOTAM_DETAIL_ID = e.prssd_notam_pk
where s.item_b_date <= TO_DATE('2021-4-22 13:28:00','yyyy-mm-dd hh24:mi:ss')
and s.item_c_date >= TO_DATE('2021-4-22 13:28:00','yyyy-mm-dd hh24:mi:ss')
and (e.item_b_real_date is null or e.item_c_real_date is null or (e.item_b_real_date is not null and e.item_c_real_date is not null and e.item_c_real_date > e.item_b_real_date))
)
3、还有一种说法是利用每条记录的rowid不同过滤,通过not exist选出rowid最小的或rowid最大的数据,我还没有搞明白,暂时不做记录