Oracle查询未过滤预期结果

时间:2016-02-29 12:15:57

标签: asp.net oracle

我有一个调试过的查询,其中我添加了一个像

这样的条件
AND cp.area = 'Like upper(%Aarey%)'

对于 Aarey ,结果存在于数据库中,但它不会获取任何记录。

以下是我的调试查询

SELECT   CASE type_of_channel_p
        WHEN '10'
           THEN 'Broker'
        WHEN '30'
           THEN 'International Property Consultant'
     END type_of_cp,
     CASE cp.type_of_firm
        WHEN '10'
           THEN 'Asset Consultant'
        WHEN '20'
           THEN 'Estate Consultant'
        WHEN '30'
           THEN 'Broker'
        WHEN '40'
           THEN 'Housing Agency'
        WHEN '50'
           THEN 'Partnership Firm'
        WHEN '60'
           THEN 'Property consultant'
        WHEN '70'
           THEN 'Sole selling broker'
        WHEN '80'
           THEN 'International Property Consultant'
     END type_of_firm,
     CASE
        WHEN ld.broker_id > 0
           THEN 'Broker'
        ELSE 'New'
     END cp_type, rating,
     TO_CHAR (cp.creation_date, 'dd/mm/yyyy') entry_date, cp.mkey,
     TO_CHAR (cp.date_of_introduction, 'dd/mm/yyyy') date_of_introduction,
     cp.name_of_firm, cp.pan_no, cp.service_tax_no,
        cp.address1
     || ' '
     || cp.address2
     || ' '
     || cs.city
     || ' ' || cp.pin_code
     || ' '
     || cs.state
     || ' '
     || cs.country_name address,
     a.area, ct.city, st.state, cn.country_name country, cp.person_name,
     cp.mobile, cp.landline, cp.email_id, ev.description created_by,
     ev1.description introduced_by, cp.remarks remarks,
     cp.remarks remarks1, fm.sr_no, fm.sr_no followup_srno,
     fm.follow_up_type, fm.activity_description,
     TO_CHAR (fm.next_follow_up_date, 'dd/mm/yyyy') next_follow_up_date,
     fm.next_to_do_activity next_activity, fm.commen comments,
     fm.commen comments1,
     TO_CHAR (cp.rating_update_date, 'dd/mm/yyyy') rating_update_date,
     cm.meeting_name
FROM xxcus.xxacl_pn_new_cha_part cp,
     xxcus.xxacl_pn_type_of_firm_v tf,
     (SELECT DISTINCT broker_id
                 FROM xxcus.xxacl_pn_lease_det ld
                WHERE ld.sr_no = 1
                  AND broker_flag = 'C'
                  AND ld.broker_id > 0) ld,
     xxcus.xxacl_pn_city_state_v cs,
     apps.fnd_user ev,
     apps.fnd_user ev1,
     xxcus.xxacl_pn_ncp_followup_max_v fm,
     xxcus.xxacl_pn_city_area_v a,
     xxcus.xxacl_pn_city_v ct,
     xxcus.xxacl_pn_state_v st,
     xxcus.xxacl_pn_country_v cn,
     xxcus.xxacl_pn_cp_meeting_v cm WHERE cp.delete_flag = 'N'
 AND cp.mkey = fm.mkey(+)
 AND cp.type_of_firm = tf.firm_id(+)
 AND cp.broker_id = ld.broker_id(+)
 AND cp.city = cs.city_code(+)
 AND cp.created_by = ev.user_id
 AND cp.introduced_by = ev1.user_id
 AND cp.area = a.area_code(+)
 AND ct.city_code(+) = cp.city
 AND st.state_code(+) = cp.state
 AND cp.cp_meeting = cm.meeting_code(+)
 AND cn.country_id(+) = cp.country
 AND cp.area = 'Like upper(%Aarey%)' ORDER BY cp.creation_date DESC,
     ev.description,
     cp.date_of_introduction,
     fm.next_follow_up_date

请建议查询有什么问题,我的条件是否未正确执行或其他?

2 个答案:

答案 0 :(得分:2)

嗯,你的情况似乎错了..

如果要检查cp.area是否包含字符串AAREY

,请尝试这样的操作
AND cp.area LIKE '%AAREY%'

或者如果它是一个列,那么使用concat:

AND cp.area LIKE concat('%',upper(Aarey),'%')

答案 1 :(得分:0)

我相信     AND cp.area ='喜欢上层(%Aarey%)'

应该是`upper(cp.area)喜欢'%AAREY%'