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 -> What went wrong with this Function First?

What went wrong with this Function First?

From: <dennis.pong_at_gmail.com>
Date: 6 Dec 2006 13:06:19 -0800
Message-ID: <1165439179.660280.69400@80g2000cwy.googlegroups.com>


Hi,

I'm trying to flag the first record within each group of individual_id

For example,

INDIVIDUAL_ID                                         FIRST_FLAG
1447620	7/30/2005	               C	1
1447620	7/21/2005	               C	0
1447620	7/15/2005	               D	0
1447620	6/30/2005	               D	0
1840354	12/1/2006	               Z	1
1840354	11/28/2006               D	0
1840354	11/28/2006               D	0
1840354	11/28/2006               D	0

HERE IS MY FUNCTION  CREATE OR REPLACE Function First

    ( individual_id IN number )
    RETURN number

        IS
    stored_ind_id number(8);

        ind_first number(1);

    cursor c1 is

      select individual_id, activity_date , lead_grade
      from IND_ACTS
	  GROUP BY individual_id, activity_date , lead_grade
	  ORDER BY individual_id, activity_date desc, lead_grade;


BEGIN stored_ind_id := 0;
ind_first := 0;

FOR IND_ACTS in c1
LOOP

	If stored_ind_id <> individual_id then
	   	stored_ind_id := individual_id;
		ind_first := 1;

	END IF;


END LOOP; RETURN ind_first;

END; Don't know if someone could point out the possible flaws of this function that it doesn't work as expected.

Thanks, Received on Wed Dec 06 2006 - 15:06:19 CST

Original text of this message

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