I am sure where it is occurring when I apply below in the Oracle database.
SELECT H.MAQUINA,
PR.COD,
H.TURNO
FROM HISTORICO,
(SELECT DISTINCT(P.ID) AS PID, P.CODIGO AS COD
FROM PRODUTO P, TEXTO_LOCALD TL
WHERE P.TEXTOID = TL.ID AND LINGUAGEM = 1) PR
WHERE PR.PID = H.PRODUTOID
AND H.SEQUENCIA LIKE '0001%'
AND H.CLASSE = 1
AND H.DATA_TRAB = TO_DATE('2016-08-28','YYYY-MM-DD')
AND H.TURNO IN (1,2,3)
AND PR.COD IN (6383,4407,4485,4496,4501)
GROUP BY H.MAQUINA,PR.COD,H.TURNO
/
What happens, when he first consulted it usually performs, however, if it is again the same consultation. The error occurs ORA-01722: invalid number .
After analyzing I checked that product codes with letters were also registered in the product table and put apostrophes in this clause
PR.COD IN ('6383','4407','4485','4496','4501')
My question is the following, why Oracle performs the query the first time and the second time it occurs error? I made the query on other dates and some occurs the error and in others no error occurs.
The bank used is Oracle 11g.