ORACLE SQL:喜欢CONTAINS

时间:2017-11-10 08:30:08

标签: sql oracle

我迫切希望在此查询(下面)中将LIKE更改为CONTAINS函数(最后一个WHERE表达式)。它与LIKE一起使用很好,但是当我将LIKE改为CONTAINS然后我收到错误时,我花了很多时间来修复它。错误是:

  

[42000] [979] ORA-00979:不是GROUP BY表达式

查询是:

META-INF/services

我将此查询更改为:

select id, 
       agr_numbers,
               vehicle_reg_numbers
            FROM (
            select id 
                   ,(select listagg(column_value, ', ') within group (order by column_value) from table(coll_names)) as agr_numbers
                   ,vehicle_reg_numbers
           ,event_date_sortable
            from (
              select clme.id
            ,clme.vehicle_reg_numbers
                    ,collect(distinct nvl(agr.agreement_number,cea.agreement_number)) as coll_names
            ,clme.event_date_sortable
                FROM 
                v_clm_event_list clme
                LEFT JOIN adm_address adr ON clme.aav_adm_address_id = adr.id
                    LEFT JOIN clm_claim_case ccc ON clme.id = ccc.clm_event_id
                    LEFT JOIN agr_agreement agr ON agr.id = ccc.agr_agreement_id
                    LEFT JOIN clm_ext_agreement cea ON ccc.id = cea.clm_claim_case_id
                WHERE
                    1=1
                GROUP BY clme.id
                         ,clme.vehicle_reg_numbers
                         ,clme.event_type_id
           ,clme.event_date_sortable
                HAVING 1=1       
            ) ) q
            WHERE vehicle_reg_numbers LIKE '%';

...........

select SCORE(1), id,
       agr_numbers,......

然后我得到上面显示的错误。 我明白,我需要提出

WHERE CONTAINS (vehicle_reg_numbers, '%', 1) > 0
            ORDER BY SCORE(1) DESC, id,
               agr_numbers,
               vehicle_reg_numbers;

要GROUP BY,但我不知道怎么做。请帮忙! 我真的需要使用CONTAINS,我阅读文档,没有运气。我试过很多形式的CONTAINS,没有运气。我真的很感激任何帮助!

1 个答案:

答案 0 :(得分:0)

如果不在SELECT子句中添加agr.agreement_number和cea.agreement_number,则不能在GROUP BY中使用它们。 因此,请尝试更改GROUP BY

GROUP BY clme.id
  ,clme.vehicle_reg_numbers
  ,clme.event_type_id
  ,clme.event_date_sortable
  ,agr.agreement_number
  ,cea.agreement_number

或使用MINMAXSUM

等功能