Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Newbie cursor question

Re: Newbie cursor question

From: Marc Billiet <E.Mail_at_address.com>
Date: Wed, 16 Aug 2000 08:03:47 +0200
Message-ID: <8ndb24$fll$1@vkhdsu24.hda.hydro.com>

A possibility may be (but whether this is clean and elegant programming is up to you to decide):

DECLARE
  e_continue EXCEPTION;
  CURSOR cur_employees IS ...;
BEGIN
  FOR emp_record IN cur_employees
  LOOP
    BEGIN

      IF condition THEN
        RAISE  e_continue;
      END IF;

      -- start real processing here
      ...
    EXCEPTION
      WHEN e_continue THEN
         NULL;

    END;
  END LOOP;
END; Another (and IMO better) solution is to split up your code into smaller functions (in a package):

PACKAGE xxx IS
  CURSOR cur_employees IS ...;

  FUNCTION check_conditions(p_emp_record IN cur_employees%ROWTYPE)   RETURN BOOLEAN
  IS
  BEGIN
    RETURN (condition);
  END check_conditions;

  PROCEDURE real_processing(p_emp_record IN cur_employees%ROWTYPE)   IS
  BEGIN

  PROCEDURE main
  IS
  BEGIN
    FOR emp_record IN cur_employees
    LOOP

      IF check_conditions(emp_record) THEN
        real_processing(emp_record);
      END IF;

    END LOOP;
  END main;
END xxx;

Marc

Lisa Adcock wrote in message <8murv1$fqq2_at_eccws12.dearborn.ford.com>...
>I have a cursor and I would like to do some data validation on each row in
>the cursor before the "real" processing begins. I would like to organize
 my
>as follows but am having problems finding the right language
>construct/reserved word.
>
>for emp_record in cur_employees loop
>
> if this row has a data problem then
> continue onto next row in cursor
> end if
>
> -- start real processing here
>
>end
>
>I can solve my problem by putting the "real" processing in the elsif part
 of
>the if statement, but the processing logic already involves three nested
 ifs
>and I don't want to indent them another level by putting them in the elsif.
>
>Any ideas would be appreciated!
>
>
Received on Wed Aug 16 2000 - 01:03:47 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US