jeudi 25 juin 2015

Rewrite If-else block using For loop

How can I write the following If-else block using for loop:

    BEGIN
        IF :new.plan_id = 1 THEN
          SELECT PLAN_MAX_START_HH24 INTO NEW_PLAN_MAX_START_HH24 FROM screening_plan WHERE plan_id = 1; 
          SELECT PLAN_MIN_START_HH24 INTO NEW_PLAN_MIN_START_HH24 FROM screening_plan WHERE plan_id = 1;
        ELSIF :new.plan_id = 2 THEN
          SELECT PLAN_MAX_START_HH24 INTO NEW_PLAN_MAX_START_HH24 FROM screening_plan WHERE plan_id = 2; 
          SELECT PLAN_MIN_START_HH24 INTO NEW_PLAN_MIN_START_HH24 FROM screening_plan WHERE plan_id = 2;
        ELSIF :new.plan_id = 3 THEN
          SELECT PLAN_MAX_START_HH24 INTO NEW_PLAN_MAX_START_HH24 FROM screening_plan WHERE plan_id = 3; 
          SELECT PLAN_MIN_START_HH24 INTO NEW_PLAN_MIN_START_HH24 FROM screening_plan WHERE plan_id = 3;
        ELSIF :new.plan_id = 4 THEN
          SELECT PLAN_MAX_START_HH24 INTO NEW_PLAN_MAX_START_HH24 FROM screening_plan WHERE plan_id = 4; 
          SELECT PLAN_MIN_START_HH24 INTO NEW_PLAN_MIN_START_HH24 FROM screening_plan WHERE plan_id = 4;
        END IF;
     END;

For some plan_id with values 1,2,3,4 , I have to select the plan_max_start_hh24 and plan_min_start_hh24.

Aucun commentaire:

Enregistrer un commentaire