Search code examples
oraclesql-likebetween

The between and like functions with dates


I ran these two scripts below and they give two different results. The first did not include data for the 30th of April but the latter does. I am using oracle sql. Could someone assist?

select distinct * from a where (m_date between'01-MAY-17' AND '30-MAY-17');

select distinct * from a where m_date like '%-MAY-17';

Solution

  • I used the to_date function and it worked:

    select distinct * from a where to_date (m_date) between'01-MAY-17' AND '30-MAY-17'

    This produced the same results as with the like clause:

    select distinct * from a where m_date like '%-MAY-17'