Вопрос

I want to replace the hour on a date, for instance, if I have 07/07/13 11:15, I'll want to get 07/07/13 00:00 from the first date.

So, what I'm trying to do is this:

textDate := TO_CHAR (auxDate, 'DD/MM/RR')||' '||textHour||':'||textMin;
endDate := TO_DATE(textDate, 'DD/MM/RR hh:mm');

When I run the SP, it gives me the following error:

ORA-01810: format code appears twice

auxDate is declared as DATE, textDate as VARCHAR2(20), endDate is DATE.

Can you help me solve this?

Это было полезно?

Решение 2

Reset your date to midnight and then add required amount of hours and minutes.

endDate := trunc(auxDate) + textHour/24 + textMin/24/60;

Другие советы

you have a typo in to_date format. it must be mi and not mm

endDate := TO_DATE(textDate, 'DD/MM/RR hh:mi');
DECLARE
    textDate_YYYYMMDD VARCHAR2(8)  := '20130101';
    textDate_HH       VARCHAR2(2)  := '13';
    textDate_MM       VARCHAR2(2)  := '15';
    textDate_mask     VARCHAR2(14) := 'YYYYMMDDHH24MI';
    textDate          DATE         := TO_DATE(textDate_YYYYMMDD || textDate_HH || textDate_MM, textDate_mask);
BEGIN
    DBMS_OUTPUT.PUT_LINE(TO_CHAR(textDate, textDate_mask));
END;
/*
anonymous block completed
201301011315
*/
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top