2016-04-21 88 views
0

對於我的一列查詢,我想要一個CASE語句。CASE不在oracle中工作

的情況是

如果我的列名ltt.f_complete task_completed0則該值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 

好心建議什麼是錯的

UPDATE

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 

回答

2

您缺少的關鍵字是END。它應該這樣寫:

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

現在收到錯誤爲'ORA-00923:FROM關鍵字未找到其中expected' – BNN

+0

@coder更新您原來的問題,以反映你是從獲得新的錯誤實際查詢。 –

+0

那麼你應該在'END'之後加''',我想。你能更新你的查詢嗎? –