Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Mixing case statement with Nested ifs

Richie VSep 30 2015 — edited Sep 30 2015

Hello I need to mix a case statement with some nested ifs but I'm receiving an error I don't know how to start or end the case statement properly. I shortened the FOR statement for readability

Here is the code:

<tt>

BEGIN

FOR events IN (SELECT EBA_CA_EVENTS.EVENT_NAME, EBA_CA_EVENTS.EVENT_ID,....)

LOOP

if events.TYPE_ID <> (32230291965131516245569156552736940921) AND to_date(SYSDATE) = ((to_date(to_char(events.EVENT_DUE_DATE, 'YYYY-MON-DD HH24:MI:SS'), 'YYYY-MON-DD HH24:MI:SS')) - events.EVENT_NOT1)

THEN

DBMS_OUTPUT.put_line ('Criteria fits SEND EMAIL Alert 1');

else

if events.TYPE_ID = (32230291965131516245569156552736940921) and nvl(events.COMPLETED_MAIL_SENT,0) <> ('S')

THEN

DBMS_OUTPUT.put_line ('SEND COMPLETED EMAIL TO TERRY');

                  UPDATE EBA\_CA\_EVENTS set COMPLETED\_MAIL\_SENT = ('S') where ROW\_KEY=events.ROW\_KEY;

else

if events.TYPE_ID <> (32230291965131516245569156552736940921) AND to_date(SYSDATE) = ((to_date(to_char(events.EVENT_DUE_DATE, 'YYYY-MON-DD HH24:MI:SS'), 'YYYY-MON-DD HH24:MI:SS')) - events.EVENT_NOT2)

THEN

DBMS_OUTPUT.put_line ('2nd Criteria fits SEND EMAIL Alert 2');

else

if events.TYPE_ID <> (32230291965131516245569156552736940921) AND to_date(SYSDATE) = ((to_date(to_char(events.EVENT_DUE_DATE, 'YYYY-MON-DD HH24:MI:SS'), 'YYYY-MON-DD HH24:MI:SS')) - events.EVENT_NOT3)

THEN

DBMS_OUTPUT.put_line ('3rd Criteria fits SEND EMAIL Alert 3');

end if; -- 4

end if; -- 3

end if; -- 2

end if; -- 1

CASE

WHEN events.EVENT_NOT2 is NULL

THEN

if to_date(SYSDATE) > ((to_date(to_char(events.EVENT_DUE_DATE, 'YYYY-MON-DD HH24:MI:SS'), 'YYYY-MON-DD HH24:MI:SS')) - events.EVENT_NOT1) AND nvl(events.ALERT1_SENT, 0) <> ('S')

THEN

DBMS_OUTPUT.put_line (' send email if date past part 1');

UPDATE EBA_CA_EVENTS set ALERT1_SENT = ('S') where ROW_KEY=events.ROW_KEY;

end if;

END

else case

WHEN events.EVENT_NOT2 is NOT NULL

THEN

if to_date(SYSDATE) > ((to_date(to_char(events.EVENT_DUE_DATE, 'YYYY-MON-DD HH24:MI:SS'), 'YYYY-MON-DD HH24:MI:SS')) - events.EVENT_NOT1) AND nvl(events.ALERT1_SENT, 0) <> ('S') AND to_date(SYSDATE) < ((to_date(to_char(events.EVENT_DUE_DATE, 'YYYY-MON-DD HH24:MI:SS'), 'YYYY-MON-DD HH24:MI:SS')) - events.EVENT_NOT2)

        THEN

DBMS_OUTPUT.put_line ('if date past part 2 with value');

UPDATE EBA_CA_EVENTS set ALERT1_SENT = ('S') where ROW_KEY=events.ROW_KEY;

end if;

END

END LOOP;

END

</tt>

The error is occurring around the end of the case statement -- case.PNG

I also tried this removing the "else" before the case and a few other variations I just can't perfect the code though, any help would be appreciated, thanks

BTW I can't use IF.... THEN logic I already tried it and once a particular branch comes true then the else statements are bypassed.

This post has been answered by jaramill on Sep 30 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 28 2015
Added on Sep 30 2015
14 comments
498 views