0
我一直在嘗試是否可以有條件地連接兩個表。下面是我做的一個例子,但它返回一個錯誤ORA-00905:缺少關鍵字。在加入聲明中使用案例Oracle
WITH rejects AS
(
SELECT
c.containername
, c.containerid
, rlhd.waferscribenumber
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_BLISTER', rlhd.totalqty)), 0) WLP_BLISTER
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_CAMTEKREJECTS', rlhd.totalqty)), 0) WLP_CAMTEKREJECTS
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_CHIP-OUT', rlhd.totalqty)), 0) WLP_CHIPOUT
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_LIQUID_CONTAM', rlhd.totalqty)), 0) WLP_LIQUID_CONTAM
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_OPAQUE_CONTAM', rlhd.totalqty)), 0) WLP_OPAQUE_CONTAM
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_CORROSION', rlhd.totalqty)), 0) WLP_CORROSION
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_CRACKED_OR_BROKEN_WAFER', rlhd.totalqty)), 0) WLP_CRACKED_OR_BROKEN_WAFER
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_DIFFUSION_FAULT', rlhd.totalqty)), 0) WLP_DIFFUSION_FAULT
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_EDGE_DIE', rlhd.totalqty)), 0) WLP_EDGE_DIE
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_EXCESSMETAL', rlhd.totalqty)), 0) WLP_EXCESSMETAL
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_EXCESS_PROBE_MARK', rlhd.totalqty)), 0) WLP_EXCESS_PROBE_MARK
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_FADED_INK', rlhd.totalqty)), 0) WLP_FADED_INK
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_FLY-OFF_DIE', rlhd.totalqty)), 0) WLP_FLYOFF_DIE
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_FOREIGN_MATERIALS', rlhd.totalqty)), 0) WLP_FOREIGN_MATERIALS
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_GLASSIVATION', rlhd.totalqty)), 0) WLP_GLASSIVATION
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_INCOMPLETETRIM', rlhd.totalqty)), 0) WLP_INCOMPLETETRIM
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_INK_SPLATTER', rlhd.totalqty)), 0) WLP_INK_SPLATTER
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_LASERPINHOLE', rlhd.totalqty)), 0) WLP_LASERPINHOLE
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_LASERTRIM', rlhd.totalqty)), 0) WLP_LASERTRIM
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_LIGHT_HAZES', rlhd.totalqty)), 0) WLP_LIGHT_HAZES
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_METAL_BRIDGE', rlhd.totalqty)), 0) WLP_METAL_BRIDGE
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_METAL_VOID', rlhd.totalqty)), 0) WLP_METAL_VOID
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_MISALIGN_SCRIBE', rlhd.totalqty)), 0) WLP_MISALIGN_SCRIBE
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_OTHERS', rlhd.totalqty)), 0) WLP_OTHERS
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_PASSIVATION_FAULT', rlhd.totalqty)), 0) WLP_PASSIVATION_FAULT
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_PROBE_DAMAGE', rlhd.totalqty)), 0) WLP_PROBE_DAMAGE
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_METAL_SCRATCH_OVER', rlhd.totalqty)), 0) WLP_METAL_SCRATCH_OVER
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_METAL_SCRATCH_UNDER', rlhd.totalqty)), 0) WLP_METAL_SCRATCH_UNDER
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_THROWAWAY_DIES', rlhd.totalqty)), 0) WLP_THROWAWAYDIES
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_UNPROBE_DIE', rlhd.totalqty)), 0) WLP_UNPROBE_DIE
, NVL(MAX(DECODE(rlhd.LossReasonName, 'WLP_WO_LETTER_EFG', rlhd.totalqty)), 0) WLP_WO_LETTER_EFG
FROM CONTAINER c
JOIN a_rejectlothistory rlh ON c.containerid = rlh.historyid
JOIN a_rejectlothistorydetails rlhd ON rlh.rejectlothistoryid = rlhd.rejectlothistoryid
WHERE rlhd.specname IN ('8810_DS_VISUAL_INS_WS', '8810_WS_VISUAL_INS_WS', '7202_POST_WAFFLE_PACK_INSPECTION_WS')
GROUP BY c.containername
, c.containerid
, rlhd.waferscribenumber
ORDER BY c.containername
)
SELECT DISTINCT
SUBSTR((SELECT(otherdb.pkg_calendar.fncalendar(wl.moveouttimestamp, 'YYYYWW')) AS wwkdate FROM dual), 0, LENGTH((SELECT(otherdb.pkg_calendar.fncalendar(wl.moveintimestamp, 'YYYYWW')) AS wwkdate FROM dual))-2) YEAR
, SUBSTR((SELECT(otherdb.pkg_calendar.fncalendar(wl.moveouttimestamp, 'YYYYQ')) AS wwkdate FROM dual), -1) quarter
, SUBSTR((SELECT(otherdb.pkg_calendar.fncalendar(wl.moveouttimestamp, 'YYYYWW')) AS wwkdate FROM dual), -2) WW
, to_char(wl.moveouttimestamp, 'MM/DD/YYYY HH:MI:SS PM') ddate
, CASE WHEN to_char(wl.moveouttimestamp, 'HH24') > 18 THEN 'C3' ELSE 'A2' END shift
, c.containername Lotnum
, wl.productname device
, lw.wafernumber
, p.description CATEGORY
, wl.moveinqty qty_in
, wl.moveoutqty qty_out
, DECODE(wl.moveinqty, 0, 'N/A', ROUND((wl.moveoutqty/wl.moveinqty) * 100, 4)) yield
, NVL(r.WLP_BLISTER, 0) WLP_BLISTER
, NVL(r.WLP_CAMTEKREJECTS, 0) WLP_CAMTEKREJECTS
, NVL(r.WLP_CHIPOUT, 0) WLP_CHIPOUT
, NVL(r.WLP_LIQUID_CONTAM, 0) WLP_LIQUID_CONTAM
, NVL(r.WLP_OPAQUE_CONTAM, 0) WLP_OPAQUE_CONTAM
, NVL(r.WLP_CORROSION, 0) WLP_CORROSION
, NVL(r.WLP_CRACKED_OR_BROKEN_WAFER, 0) WLP_CRACKED_OR_BROKEN_WAFER
, NVL(r.WLP_DIFFUSION_FAULT, 0) WLP_DIFFUSION_FAULT
, NVL(r.WLP_EDGE_DIE, 0) WLP_EDGE_DIE
, NVL(r.WLP_EXCESSMETAL, 0) WLP_EXCESSMETAL
, NVL(r.WLP_EXCESS_PROBE_MARK, 0) WLP_EXCESS_PROBE_MARK
, NVL(r.WLP_FADED_INK, 0) WLP_FADED_INK
, NVL(r.WLP_FLYOFF_DIE, 0) WLP_FLYOFF_DIE
, NVL(r.WLP_FOREIGN_MATERIALS, 0) WLP_FOREIGN_MATERIALS
, NVL(r.WLP_GLASSIVATION, 0) WLP_GLASSIVATION
, NVL(r.WLP_INCOMPLETETRIM, 0) WLP_INCOMPLETETRIM
, NVL(r.WLP_INK_SPLATTER, 0) WLP_INK_SPLATTER
, NVL(r.WLP_LASERPINHOLE, 0) WLP_LASERPINHOLE
, NVL(r.WLP_LASERTRIM, 0) WLP_LASERTRIM
, NVL(r.WLP_LIGHT_HAZES, 0) WLP_LIGHT_HAZES
, NVL(r.WLP_METAL_BRIDGE, 0) WLP_METAL_BRIDGE
, NVL(r.WLP_METAL_VOID, 0) WLP_METAL_VOID
, NVL(r.WLP_MISALIGN_SCRIBE, 0) WLP_MISALIGN_SCRIBE
, NVL(r.WLP_OTHERS, 0) WLP_OTHERS
, NVL(r.WLP_PASSIVATION_FAULT, 0) WLP_PASSIVATION_FAULT
, NVL(r.WLP_PROBE_DAMAGE, 0) WLP_PROBE_DAMAGE
, NVL(r.WLP_METAL_SCRATCH_OVER, 0) WLP_METAL_SCRATCH_OVER
, NVL(r.WLP_METAL_SCRATCH_UNDER, 0) WLP_METAL_SCRATCH_UNDER
, NVL(r.WLP_THROWAWAYDIES, 0) WLP_THROWAWAYDIES
, NVL(r.WLP_UNPROBE_DIE, 0) WLP_UNPROBE_DIE
, NVL(r.WLP_WO_LETTER_EFG, 0) WLP_WO_LETTER_EFG
, wl.specname
FROM CONTAINER c
JOIN product p ON c.productid = p.productid
JOIN a_wiplothistory wl ON c.containerid = wl.containerid
JOIN a_lotwafers lw ON c.containerid = lw.containerid
LEFT JOIN rejects r ON CASE WHEN wl.specname = '8810_WS_VISUAL_INS_WS' THEN c.containerid = r.containerid AND lw.waferscribenumber = r.waferscribenumber
ELSE c.containerid = r.containerid
END
WHERE c.containername NOT LIKE '%TEST%' AND c.containername NOT LIKE '%TST%' AND wl.specname IN ('8810_DS_VISUAL_INS_WS', '7202_POST_WAFFLE_PACK_INSPECTION_WS', '8810_WS_VISUAL_INS_WS')
;
關於如何實現這一點的任何想法?謝謝。
哪一行是錯誤指向的? –