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!

how do i loop through a pl/sql collection based on a condition.

oratechsOct 11 2013 — edited Oct 14 2013

hi, can any one help me or provide me sample code where  i have to loop through a collection  based on condition . just like where clause in sql. your help is highly appreciated....

{code}

create table MODEL1

(

  model_id  NUMBER ,

  model_seq NUMBER,

  p_ind     VARCHAR2(1)

);

insert into model1 (MODEL_ID, MODEL_SEQ, P_IND)

values (4, 103, 'U');

insert into model1 (MODEL_ID, MODEL_SEQ, P_IND)

values (3, 102, 'P');

insert into model1 (MODEL_ID, MODEL_SEQ, P_IND)

values (2, 101, 'U');

insert into model1 (MODEL_ID, MODEL_SEQ, P_IND)

values (1, 100, 'P');

MODEL PROCEDURE......

procedure (  param1,param2)        ( assume this procedure is being called from other procedure and collection has been populated already)

TYPE  l_tab is table of  MODEL1%rowtype;

begin

loop through l_tab records where  ltab.model_id=param1  and  p_ind =p

Join based on if else condition.

if   param2 is not null then

   l_tab.model_seq=param2 and ltab.p_ind='P'

if param2 is null then

         l_tab.p_ind='P'          etc...........

   {code}

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 11 2013
Added on Oct 11 2013
4 comments
1,937 views