Oracle date comparison in where clause

前端 未结 3 812
抹茶落季
抹茶落季 2021-01-06 05:05

For eg I have a student table with a DOJ(date of joining) column with its type set as DATE now in that I have stored records in dd-mon-yy format.

I have an IN param

3条回答
  •  礼貌的吻别
    2021-01-06 05:44

    The below should do what you've described. If not, provide more information on how "nothing seems to work".

    -- Get the count of students with DOJ = 25-AUG-1992
    SELECT COUNT(1)
    FROM STUDENT
    WHERE TRUNC(DOJ) = TO_DATE('25/AUG/1992','dd/mon/yyyy');
    

    The above was pulled from this answer. You may want to look at the answer, because if performance is critical to you, there is a different way to write this query which doesn't use trunc, which will allow Oracle to use index on DOJ, if one is present.

提交回复
热议问题