Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2003
    Posts
    1,074

    Unanswered: Loop through variables in TYPE

    Is there a way to programmatically loop over the items in a TYPE variable. Something like:

    Code:
    declare
      TYPE addrin is RECORD (
           f1 number,
    	   f2 varchar2(10));
      new_addr addrin;
    begin
      new_addr.f1 := 5;
      new_addr.f2 := 'CHuck';
      for i in 0 .. new_addr.count
      loop
        dbms_output.put_line(new_addr(i);
      end loop;
    end;

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Wink


    Try this:
    Code:
    Set Serverout On Size 1000000;
    Declare
      Type Addrin Is Record (
            F1 Number,
            F2 Varchar2(10));
      Type Addrin_Array Is Table Of Addrin Index By Binary_Integer;
      New_Addr Addrin_Array;
      I Pls_Integer;
    Begin
      New_Addr(1).F1 := 5;
      New_Addr(1).F2 := 'Chuck';
      New_Addr(2).F1 := 7;
      New_Addr(2).F2 := 'Forbes';
      For I In 1..New_Addr.Last
      Loop
        Dbms_Output.Put_Line(New_Addr(I).F1||' Is '||New_Addr(I).F2);
      End Loop;
    End;
    /

    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  3. #3
    Join Date
    Dec 2003
    Posts
    1,074
    I was looking to loop over the variables in the RECORD, rather than the RECORDs in a TABLE. Do you think that's possible?

    --=cf

  4. #4
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    No. With a TYPE defined in the database (i.e. by a CREATE TYPE statement) you should be able to get a list of the attributes from the data dictionary and use that to construct some dynamic PL/SQL - but I wouldn't go to all that trouble unless I was building something very generic (like Toad).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •