CASE不在oracle工作

时间:2016-04-21 09:54:35

标签: oracle

对于我的一个查询列,我想要一个CASE语句。

情景是

如果我的列名ltt.f_complete task_completed值为0,那么值shd为NO,如果1则为YES

我尝试过以下但是得到了

  

ORA-00905:缺少关键字

这是查询

SELECT flv.property_name project_name, flv.building building_name,
   flv.flat_no unit_no,
      ldet.customer_fname
   || ' '
   || ldet.customer_mname
   || ' '
   || ldet.customer_lname customer_name,
   la.booking_date holding_date, ltt.start_date task_date,
   tid.task_desc task_type, fol.next_follow_up_date,
   ltt.remarks task_comment, ltt.f_complete task_completed,
   CASE TASK_VALUE WHEN '0' THEN 'NO'
   WHEN '1' THEN 'YES',
   act.act_desc activity_description, flv.follow_type followup_type,
   fol.remarks followup_comment,
   fol.next_follow_up_date next_followup_date,
   actt.act_desc next_todo_activity
   FROM xxcus.xxacl_pn_leases_all la,
     (SELECT *
        FROM xxcus.xxacl_pn_lease_det
       WHERE sr_no = 1) ldet,
     xxcus.xxacl_pn_lease_task_trl ltt,
     xxcus.xxacl_pn_customer_followup fol,
     xxacl_pn_flat_det_v flv,
     xxcus.xxacl_pn_hold_task_v tid,
     xxcus.xxacl_pn_hold_act_v act,
      xxcus.xxacl_pn_followup_type_v flv,
      xxcus.xxacl_pn_hold_act_v actt
  WHERE la.booking_no = ltt.draft_form_no(+)
   AND ltt.draft_form_no = fol.booking_no(+)
   AND ltt.task_id = fol.task_id(+)
  AND ltt.task_sr_no = fol.task_sr_no(+)
  AND la.delete_flag = 'N'
   AND la.booking_no = ldet.booking_no
  AND fol.followup_date = TO_DATE (SYSDATE - 1)
   AND la.flat_id = flv.flat_id
  AND ltt.task_id = tid.task_id
  AND fol.activity_id = act.act_id
  AND fol.followup_type_id = flv.follow_type_id
  AND fol.next_activity_id = actt.act_id

请提出错误的建议

更新

SELECT flv.property_name project_name, flv.building building_name,
   flv.flat_no unit_no,
      ldet.customer_fname
   || ' '
   || ldet.customer_mname
   || ' '
   || ldet.customer_lname customer_name,
   la.booking_date holding_date, ltt.start_date task_date,
   tid.task_desc task_type, fol.next_follow_up_date,
   ltt.remarks task_comment, ltt.f_complete task_completed,       
   act.act_desc activity_description, flv.follow_type followup_type,
   fol.remarks followup_comment,
   fol.next_follow_up_date next_followup_date,
   actt.act_desc next_todo_activity
 FROM xxcus.xxacl_pn_leases_all la,
   (SELECT *
      FROM xxcus.xxacl_pn_lease_det
     WHERE sr_no = 1) ldet,
   xxcus.xxacl_pn_lease_task_trl ltt,
   xxcus.xxacl_pn_customer_followup fol,
   xxacl_pn_flat_det_v flv,
   xxcus.xxacl_pn_hold_task_v tid,
   xxcus.xxacl_pn_hold_act_v act,
   xxcus.xxacl_pn_followup_type_v flv,
   xxcus.xxacl_pn_hold_act_v actt
  WHERE la.booking_no = ltt.draft_form_no(+)
   AND ltt.draft_form_no = fol.booking_no(+)
   AND ltt.task_id = fol.task_id(+)
    AND ltt.task_sr_no = fol.task_sr_no(+)
    AND la.delete_flag = 'N'
   AND la.booking_no = ldet.booking_no
   AND fol.followup_date = TO_DATE (SYSDATE - 1)
    AND la.flat_id = flv.flat_id
   AND ltt.task_id = tid.task_id
   AND fol.activity_id = act.act_id
  AND fol.followup_type_id = flv.follow_type_id
  AND fol.next_activity_id = actt.act_id

1 个答案:

答案 0 :(得分:2)

您缺少的关键字是END。它应该是这样的:

CASE TASK_VALUE WHEN '0' THEN 'NO'
WHEN '1' THEN 'YES' END