Problem with Oracle Statement in the script

I got an Oracle database statement which displays the data of the last 7 days in my script

The statement is :

select * from TABLE_NAME
WHERE  DATETIME BETWEEN  to_char((sysdate-7,MM), 'DDMMYYYY%') AND to_char((sysdate,MM), 'DDMMYYYY%')
ORDER BY DATETIME ASC;

But, this output gives me the results of the previous months data on that particular week

How to get only this months data and not the previous months data

Perhaps you can add something like this to your where clause:

AND TO_CHAR( DATETIME, 'MM') = TO_CHAR(SYSDATE, 'MM')

still not working, its giving me an error

Should I run

oerr | grep $RANDOM

or will you tell me which one?! :wink:

What is the purpose of condition of "AND"? without and condition you don't get the desired o/p?