What is the solution to the error below?

Asked

Viewed 411 times

1

I am doing a test with some tables, and I decided to do a test with the following command :

select 1 from dual
where sysdate between trunc(:dt-inicio,'dd') and trunc(:dt-fim,'dd');

select 1 from dual
where   sysdate between trunc(:dt_inicial, 'dd') and trunc(:dt_final, 'dd') + 86399 / 86400

This code is returning me the error below:

ORA-00932: tipos de dados inconsistentes: esperava DATE obteve NUMBER
00932. 00000 -  "inconsistent datatypes: expected %s got %s"
*Cause:    
*Action:

I’ve done other tests with other types of data and it worked.

1 answer

0

Have you ever tried to do something like, using the TO_DATE?

--COM TRUNC (DAY)
SELECT 'OK' AS RESULTADO, TRUNC(sysdate, 'DAY') AS SYS_DATE,  
TRUNC(TO_DATE('18/03/2020','DD/MM/YY'), 'DAY') AS DT_INCIO, 
TRUNC(TO_DATE('19/03/2020','DD/MM/YY'), 'DAY') AS DT_FIM
FROM dual
WHERE TRUNC(sysdate, 'DAY') BETWEEN TRUNC(TO_DATE('18/03/2020','DD/MM/YY'), 'DAY') 
                      AND TRUNC(TO_DATE('19/03/2020','DD/MM/YY'), 'DAY');

--SEM TRUNC (DAY)
SELECT 1 AS RESULTADO, sysdate AS SYS_DATE,
TO_DATE('18/03/2020','DD/MM/YY') AS DT_INICIO,
TO_DATE('19/03/2020','DD/MM/YY') AS DT_FIM
FROM dual
WHERE sysdate BETWEEN TO_DATE('18/03/2020','DD/MM/YY')
                      AND TO_DATE('19/03/2020','DD/MM/YY');    

These two examples work, will only display the result of if the SYSDATE is within the values of BETWEEN.

  • Thank you for the reply.

  • Thanks for the answer. I had already used it this way. The error is giving when I put the operation " + 86399 / 86400" with the date. It is necessary to have this operation to take an average of a given time and the period I put. Ex : "01/03/2020 and 04/03/2020 ->Time the customer was served at the reception and the time he received the product"

  • In this type of calculation I convert all seconds , I make the calculation , average etc , and I reconvert for days, hours etc an example https://forum.imasters.com.br/topic/587158-diff%C3%A7a-between-dates-with-day-hour-and-minutes/? tab=comments#comment-2289792

Browser other questions tagged

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