I HAVE CREATED A PL/SQL FUNCTION , WHEN I AM USING TEO CONDITION UNDER WHEN WITH AND , IT IS NOT GETTING COMPLIED : I HAVE CREATED A PL/SQL FUNCTION , HERE I AM USING CASE STATEMENT IN WHICH I AM USING A SQL QUERY AS AN EXPRESSION. THIS IS WORKING FINE BUT , WHEN I AM USING AND UNDER WHEN CONDITION IT IS NOT GETTING COMPLIED . EVEN IF I SAY WHEN .... AND 2 > 1 , THIS IS ALSO NOT GETTING COMPILED .

IN THE BELOW CODE , COMMENTED PART IS NOT WORKING PROPERLY .

WHAT I WANT IS TO ADD ONE MORE CHECK IN MY WHEN CLAUSE . PLS ADVISE   



    create or replace function FUNCTION_NAME (date1 in varchar2,value1 in varchar2)
    RETURN date
    IS
    date2 date ;
    
    BEGIN 
    SELECT D DATE2 INTO DATE2 FROM(
    SELECT 
    CASE (SELECT TO_DATE(MAX(G.DATE3),'DD-MON-YYYY')
    FROM TABLE1 G , TABLE2 N  WHERE G.DATE3=N.DATE3)
    
    WHEN LAST_DAY(TO_DATE(DATE1,'DD-MON-YYYY'))
    /* AND MONTHS_BETWEEN (LAST_DAY(TO_DATE(SYSDATE)),
    LAST_DAY(TO_DATE(TO_CHAR(DATE1),'DD-MON-YYYY'))) */
    THEN LAST_DAY(TO_DATE(DATE1,'DD-MON-YYYY'))
    
    ELSE
    TO_DATE('31-DEC-99','DD-MON-YYYY')
    END D
    FROM DUAL
    );
    
    RETURN DATE2 ;
    END ;

