SELECT of month/year in DATES

Asked

Viewed 6,919 times

4

I need select to return all the rows that were inserted in July 2010, as shown in the example, regardless of the day. How to return this query?

SELECT * FROM FRCAST 
WHERE DATA_ID = TO_CHAR('07-2010', 'mm-yyyy');

4 answers

6


You can use the function EXTRACT 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;
  • 1

    That’s nice... I hadn’t thought of a solution to include the whole month without using BETWEEN. Take a +1

  • Leave my answer as an alternative below, but Giuliana’s answer is more elegant and readable.

1

You can also use the 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');

0

0

SELECT * FROM FRCAST 
WHERE  TO_CHAR(DATA_ID, 'mm-yyyy') ='07-2010'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.