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

    Unanswered: Oracle Magazine code sample question

    In the most recent Oracle Magazine (Nov/Dec '06), a collections demo is presented by Steve Feuerstein on page 59. There was one piece that I didn't quite understand:
    Code:
    create type food_t as object (
     name varchar2(100), food_group varchar2(100), color varchar2(100));
     
    create type meal_t as object (
     number_served integer, meal_type varchar2(100), food_served food_t);
     
    create type meals_vat
     is varray(3) of meal_t;
     
    declare
     l_one_day_of_meals meals_vat := meals_vat();
    begin
     l_one_day_of_meals.EXTEND(3);
     l_one_day_of_meals(1) := meal_t(4,'BREAKFAST',food_t('Scrambled Eggs','Protein','Yellow'));
     l_one_day_of_meals(2) := meal_t(6,'LUNCH',food_t('Deluxe Salad','Vegetables','Mostly Green'));
     l_one_day_of_meals(3) := meal_t(10,'DINNER',food_t('Tofu & Rice','Protein','White'));
    end;
    Why is the TYPE meals_vat VARRAY set up to hold 3 elements
    Code:
    create type meals_vat
     is varray(3) of meal_t;
    and then EXTENDed later to hold 3 elements again
    Code:
    declare
     l_one_day_of_meals meals_vat := meals_vat();
    begin
     l_one_day_of_meals.EXTEND(3);
     ...
    There's something fundamentally missing from my understanding here.
    Thanks,
    Chuck

  2. #2
    Join Date
    Sep 2004
    Location
    London, UK
    Posts
    565
    "varray(3) of meal_t" means it can only hold 3 elements, as a limit.

    EXTEND(3) initialises 3 elements.

    I've yet to see much use for varrays though.

Posting Permissions

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