Thanks in Advance, i use an oracle 10g. In SQL case statement we pass the value and check the case according to value and return string. But instead of returning String, i want to return an expression. Is this is possible using oracle SQL query CASE statement for returning an expression? I do the following and oracle generate an error ORA-00905:Missing Keyword
SELECT ECL_CONTROL,
CASE
WHEN ECL_CONTROL = 'N' THEN ('##0') = ('##0')
WHEN ECL_CONTROL = 'Y' THEN (NVL(IL.ECL, 'X') = NVL(IM.ECL, 'X'))
END
FROM ITEM_CONTROL WHERE ITEM_NO = '2N2907A'
But The following run successfully :
SELECT ECL_CONTROL,
CASE
WHEN ECL_CONTROL = 'N' THEN 'test'
WHEN ECL_CONTROL = 'Y' THEN 'demo'
END
FROM ITEM_CONTROL WHERE ITEM_NO = '2N2907A'
I want to use this query as the inner query and return and expression for outer query. My query is following :
SELECT LSM.ACTIVE_FLAG, LSM.ITEM_NO, IL.ECL, LSM.SERIAL_NO, IL.WAREHOUSE, IL.BIN, LSM.TOOL_STATUS_CODE,
LLG.NEXT_CAL_DATE, IM.PRODUCT_GROUP
FROM LS_SERIAL_MASTER LSM, LS_LIFE_LOG LLG, ITEM_LOCATION IL, ITEM_MASTER IM
WHERE IL.PLANT = IM.PLANT AND IL.ITEM_NO = IM.ITEM_NO
AND IM.PLANT = LSM.PLANT AND IM.ITEM_NO = LSM.ITEM_NO AND NVL(IM.PRODUCT_GROUP, 'X') = NVL('PUMP', 'X')
AND LSM.PLANT = LLG.PLANT AND LSM.ITEM_NO = LLG.ITEM_NO AND LSM.SERIAL_NO = LLG.SERIAL_NO
AND LSM.LIFE_TRANS_ID = LLG.TRANS_ID AND LLG.SERIAL_NO = IL.SERIAL_NO
AND (SELECT ECL_CONTROL,
CASE ECL_CONTROL
WHEN ECL_CONTROL = 'N' THEN ('##0' = '##0')
WHEN ECL_CONTROL = 'Y' THEN (NVL(IL.ECL, 'X') = NVL(IM.ECL, 'X'))
END AS ECL_CONTROL_TXT
FROM ITEM_CONTROL WHERE ITEM_NO = '2N2907A')
AND LLG.MAINT_LMT_ID IN('T', 'U')
AND LLG.NEXT_CAL_DATE BETWEEN TO_DATE('02/1/2014', 'MM/DD/YYYY') AND TO_DATE('02/11/2014', 'MM/DD/YYYY').
My actual task is return an expression from inner query and used in outer query.
THENclause is for returning a value, not for comparing the values. You can't use any operators withe the values being returned in theTHENclause##0or the value ofNVL(IL.ECL, 'X'), which would be fine?NVL(IL.ECL, 'X') = NVL(IM.ECL, 'X')if the value is 'N' the return value is('##0') = ('##0'). This query is act as a inner query and in inner query these return statements return an expression for where condition.ILandIMis the alias or outer query tables. if the flag is 'N' so ,we need onlytrueexpression in outer queryY, then i need to add another expression.