Start and end of a month/year last in parameter (Oracle)

Asked

Viewed 210 times

1

I need you to return the total monthly data according to the MONTH and YEAR parameter reported.

I did it this way:

WHERE a.dt_mesano_referencia between 
to_date('01/'|| :NR_MES ||'/'|| :NR_ANO ||' 00:00:00', 'dd/mm/yyyy hh24:mi:ss') and
last_day(to_date( :NR_MES ||'/'|| :NR_ANO ||' 23:59:59', 'mm/yyyy hh24:mi:ss'))

But when executing, I get the following error return:

inserir a descrição da imagem aqui

There’s another way to do it?

  • I just took your Where condition and put in a query "from Dual" and ran without errors. Are the parameters being sent correctly? There are more conditions in the consultation?

  • What kind of field dt_mesano_referencia, I executed here also worked out...

1 answer

1


Instead of seeing date and time of start and end, let’s consider in the survey only the month and year.

For this we need to truncate the date not to bring the time, then we change the time frame with the to_char, to bring only the month and year, and then compare with the parameters passed:

 WHERE TO_CHAR(TRUNC(a.dt_mesano_referencia)
              ,'mm/yyyy') = '&NR_MES' || '/' || '&NR_ANO'

Browser other questions tagged

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