I change OCI8 version for PHP and since this query dosn\'t work :
SELECT \'M\'||to_char(to_date(OD.DATE2,\'DD/MM/YYYY\'),\'MM\') PERIODE, count(*) DATA, OD.D
Assuming that OD.DATE2
is of DATE datatype, you need to explicitly convert the dates-as-strings (eg. '08/03/2015'
) into date format.
Something like:
SELECT 'M'||to_char(OD.DATE2,'MM') PERIODE,
count(*) DATA,
OD.DCCPT DCCPT
FROM BDD OD
WHERE BDD = 'phone'
AND OD.SENS = 'Ent'
AND OD.DCCPT IN ('PIOLUC')
AND OD.DATE2 BETWEEN to_date('08/03/2015', 'dd/mm/yyyy') AND to_date('08/03/2016', 'dd/mm/yyyy')
group by 'M'||to_char(OD.DATE2,'MM'),
OD.DCCPT;
Note how I have removed the to_date
from around OD.DATE2
in the select and group by lists, since it is a very bad idea to use to_date
against something that is already a DATE.
By doing so, you force Oracle to do an implicit conversion to a string, which it will do so by using your NLS_DATE_FORMAT parameter to decide what format to output the string as, before it then tries to convert it back to a date using the format mask you specified, like so:
to_date(to_char(od.date2, ''), 'DD/MM/YYYY')
If the two format masks aren't the same, you will run into errors... such as the one that prompted you to post this question!