Re: comparing dates

From: DA Morgan <damorgan_at_psoug.org>
Date: Fri, 08 Feb 2008 10:14:13 -0800
Message-ID: <1202494424.676642@bubbleator.drizzle.com>


Jorge Reyes wrote:
> Hi this is an inusual behavior for me, i have the next:
>
> SELECT (TO_CHAR(vPMM_DATETIME, 'YYYY-MM-DD') || ' 00:00:00') INTO
> vINIT_DATE FROM DUAL;
> SELECT (TO_CHAR(vPMM_DATETIME, 'YYYY-MM-DD') || ' 00:04:59') INTO
> vEND_DATE FROM DUAL;
> vFLAG := 0;
> LOOP
> IF (( TO_CHAR(TO_DATE(TO_CHAR(vPMM_DATETIME, 'YYYY-MM-DD
> HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS') >=
> TO_CHAR(TO_DATE(TO_CHAR(vINIT_DATE, 'YYYY-MM-DD HH24:MI:SS'),'YYYY-MM-
> DD HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS')) AND
> (TO_CHAR(TO_DATE(TO_CHAR(vPMM_DATETIME, 'YYYY-MM-DD HH24:MI:SS'),'YYYY-
> MM-DD HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS') <=
> TO_CHAR(TO_DATE(TO_CHAR(vEND_DATE, 'YYYY-MM-DD HH24:MI:SS'),'YYYY-MM-
> DD HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS'))) THEN
> BEGIN
> SELECT TO_CHAR(vINIT_DATE, 'YYYY-MM-DD HH24:MI:SS') INTO vRANGO FROM
> dual;
> vFLAG:=1;
> END;
> END IF;
> EXIT WHEN (vFLAG =1);
> SELECT TO_CHAR(vINIT_DATE + (1/24/60/60 *300)) INTO vINIT_DATE FROM
> DUAL;
> SELECT TO_CHAR(vEND_DATE + (1/24/60/60 *299)) INTO vEND_DATE FROM
> DUAL;
> END LOOP;
>
> so the problem is that the condition cannot be evaluated because i
> probe and never set the vFLAG:=1; so the loop is infinite, i have
> vPMM_DATETIME = '2008-01-10 11:20:15' and the goal is that the vRANGO
> must be '2008-01-10 11:20:00', everything is ok but the date compare
> is the problem please help us.
>
> thanks in advance, regards from Mexico...

Is there some point to this code? What is it you are trying to accomplish. Give us the business case not code. What is it you are doing that you think requires a loop?

And in what version of Oracle?

-- 
Daniel A. Morgan
Oracle Ace Director & Instructor
University of Washington
damorgan_at_x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org
Received on Fri Feb 08 2008 - 12:14:13 CST

Original text of this message