I have a question on how to compare YYYYMM in Oracle SQL. graduation_date is saved in string format like '200212'. I want to query rows with graduation_date from Jan 2007 to Jan 2010.
Here is my query:
select ids,
from table
where to_date(substr(graduation_date,1,6),'YYYYMM' between 'Jan-2007'and 'Jan-2010'
I got error
ORA-01858:a non-numeric character was found where a numeric was expected
Can anyone can help figure this out? Many thanks!
I found a way to compare. Since the graduation_date is saved as vchar2 format like '20021200'.Default value is '00000000'. ONLY Year & Month is saved in Graduation_date. Here is my query: select ids, from table where graduation_date between '20070100'and '20100100'
I tired some other ways advised but got ORA-01843: not a valid month error select ids, from table where to_date(substr(graduation_date,1,6),'YYYYMM' between 'Jan-2007'and 'Jan-2010'
Thank you guys but just wondering why I can't use to_date to compare in this scenario?