I need the select to return all rows that were entered in July 2010, as shown in the example, regardless of the day. How do I return this query?
SELECT * FROM FRCAST
WHERE DATA_ID = TO_CHAR('07-2010', 'mm-yyyy');
I need the select to return all rows that were entered in July 2010, as shown in the example, regardless of the day. How do I return this query?
SELECT * FROM FRCAST
WHERE DATA_ID = TO_CHAR('07-2010', 'mm-yyyy');
You can use the EXTRACT function to test pieces of a date. Your query would look like this:
SELECT * FROM FRCAST
WHERE extract(month from DATA_ID) = 7 and extract (year from DATA_ID) = 2010;
You can also use BETWEEN
:
SELECT * FROM FRCAST
WHERE DATA_ID between
TO_DATE('01/07/2010','DD/MM/YYYY') and
TO_DATE('31/07/2010 23:59:59','DD/MM/YYYY HH24:mi:ss');
SELECT * FROM FRCAST
WHERE TO_CHAR(DATA_ID, 'mm-yyyy') ='07-2010'
To do this, you can do the following:
SELECT * FROM FRCAST
WHERE TO_CHAR(DATA_ID,'MM-YYYY')='07-2010';
References:
How to select rows for a specific month
TO_CHAR (datetime)