Data in SQL ORACLE

Asked

Viewed 841 times

1

How do I apply a function in ORACLE SQL that brings me only records for the current month? BS.: I have a date column in date format (e.g.: 13/09/18).

In sql server I applied the function below and worked perfectly:

DAT_REFERENCIA>= DATEADD(MM,DATEDIFF(MM,0,GETDATE())-0,0)

2 answers

2


You can use WHERE like this:

WHERE trunc( DAT_REFERENCIA, 'MM' ) = trunc( sysdate, 'MM' )

Will take the current date of sysdate (as getdate() in the sql-server)

EDIT: To take the current and previous month, you can use the between:

WHERE DAT_REFERENCIA BETWEEN  add_months(trunc(sysdate,'MM'),-1) AND SYSDATE
  • Ricardo, I did this way that you spoke and ran cool. And if I want to pull the past month and the current month?

  • edited the question and added it there :)

  • Thanks Ricardo. It worked right. Abs.

0

Friend, use the function EXTRACT for the command that takes the current date in Oracle which is the sysdate. Below is an example:

Select extract(month from sysdate) as MES_ATUAL from dual ; 

Browser other questions tagged

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