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 to find if an array element value exists??

PaulDddddJun 8 2017 — edited Jun 8 2017

Is there any other way, other than looping the entire array, maybe using EXISTS, to find out if this array has cus_no 222?

DECLARE

TYPE cus_rec_type

IS

  RECORD

  (

    cus_no   NUMBER,

    cus_name VARCHAR2(25) );

TYPE cus_tab_type

IS

  TABLE OF cus_rec_type INDEX BY pls_integer;

  t_cus cus_tab_type;

  i PLS_INTEGER;

BEGIN

  t_cus(1).cus_no   := '111';

  t_cus(1).cus_name := 'Jack';

  t_cus(2).cus_no   := '222';

  t_cus(2).cus_name := 'Pete';

  -------

  i       := t_cus.first;

  WHILE i IS NOT NULL

  LOOP

    IF t_cus(i).cus_no = 222 THEN

      DBMS_OUTPUT.PUT_LINE('Customer # 222 found');

    END IF;

    i := t_cus.NEXT(i);

  END LOOP;

END;

This post has been answered by Paulzip on Jun 8 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 6 2017
Added on Jun 8 2017
7 comments
18,779 views