month / year SELECT in DATES

4

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');
    
asked by anonymous 17.03.2017 / 18:10

4 answers

6

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;
    
17.03.2017 / 18:17
1

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');
    
17.03.2017 / 18:46
0
SELECT * FROM FRCAST 
WHERE  TO_CHAR(DATA_ID, 'mm-yyyy') ='07-2010'
    
17.03.2017 / 19:30
0

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)

    
17.03.2017 / 18:42