ORA-06530: reference to an uninitialized composite error in oracle 10g

hi, i get the ORA-06530: reference to an uninitialized composite error whenever i try to run the script below. the script is preety well documented for your convenience. please tell me what im doing wrong

create or replace type loctype as object(
x      number,
y      number
);
/

create or replace type meastype as object(
time       int,
loc      loctype,
vel      int,
dir      number -- measured as degrees from +x axis
);
/

create or replace type meastbl as table of meastype;
/

create or replace type car as object(
lic            char(8),
meas            meastbl,
member function position(t int) return loctype,
pragma restrict_references(position, WNDS, WNPS)
);
/

create or replace type body car is
member function position(t int) return loctype is
--function position returns position of the car at time t
      
      cur_l            loctype;            --car's current location
      cur_v            int := 0;            --car's current velocity
      cur_d            number := 0;      --car's current direction                  
      max_time                      int := 0;            --max time measurement for car
      min_time                      int := 0;            --min time measurement for car
      ti            int := 0;            --an arbitrary value for time
      prv_ti            int := 0;            --previous ti
      itr            int := 0;            --iterator variable
      cursor time_cur is select time from table(meas);
                              --cursor for iterating over the meas table                                                

BEGIN
      
      --initialize cur_l
      cur_l.x := null;
      cur_l.y := null;
      
      IF(t < 0) THEN      
      --check validity of t, returns an error if t is negative
            raise_application_error(-20225, 'Time must be non-negative.');
      
      ELSE            
      --else determine course of action depending on current
      --measurements for car
      
            --determine min and max time measurements for car
            SELECT MIN(time), MAX(time) INTO min_time, max_time FROM TABLE(meas);
                  
            IF(t < min_time) THEN
            --case where only measurements after time t exists, just return null.
                  return loctype(null, null);
            
            ELSIF(t > max_time) THEN
            --case where we need to extrapolate the position of car based
            --on the last known measurement (max_time in this case)
                  SELECT loc, vel, dir INTO cur_l, cur_v, cur_d
                  FROM TABLE(meas) WHERE time = max_time;
                  
                  itr := max_time - t;

                  LOOP
                  --extrapolate position of car at time t.
                        itr := itr - 1;
                        cur_l.x := cur_l.x + (cur_v * COS(cur_d));
                        cur_l.y := cur_l.y + (cur_v * SIN(cur_d));
                        EXIT WHEN itr < 0;
                  END LOOP;
      
                  return loctype(cur_l.x,cur_l.y);
                              
            ELSE      
            --case where a measurement in time t is either known and is
            --in the db, or not known and we must extrapolate
                  SELECT loc INTO cur_l FROM TABLE(meas) WHERE time = t;
                  
                  IF(cur_l is not null) THEN
                  --mesurement already in db just return querry result
                        return cur_l;
                  ELSE
                  --find time tx where tx < t and extrapolate based
                  --on measurements on tx
                        
                        OPEN time_cur;                  
                        
                        LOOP
                        --prv_ti = tx
                              prv_ti := ti;
                              FETCH time_cur INTO ti;
                              EXIT WHEN ti >= t;
                        END LOOP;
                        
                        itr := prv_ti - t;

                        LOOP
                        --extrapolate position of car at time t.
                              itr := itr - 1;
                              cur_l.x := cur_l.x + (cur_v * COS(cur_d));
                              cur_l.y := cur_l.y + (cur_v * SIN(cur_d));
                              EXIT WHEN itr < 0;
                        END LOOP;
                                                
                        CLOSE time_cur;
                                                
                        return loctype(cur_l.x,cur_l.y);
                        
                  END IF;      
            END IF;
      END IF;

END;
END;
/

create table cartab of car nested table meas store as intmeastbl;



insert into cartab
values('1ABC1234', meastbl(meastype(10, loctype(0,0), 1, 0),
                                         meastype(15, loctype(5,0), 2, 90),
                     meastype(20, loctype(5,10), 3, 0)));


                                       
prompt test when time is less than min time for car
prompt correct asnswer would be (null,null) or something similar
select c.lic, c.position(0) from cartab c where lic like '1%';

prompt test when time is greater than max time for car.
prompt program should extrapolate
prompt correct answer is (11,10)
select c.lic, c.position(22) from cartab c where lic like '1%';

prompt test when time is in the db
prompt correct answer is (5,0)
select c.lic, c.position(15) from cartab c where lic like '1%';

prompt test when time is within min and max time
prompt but is not in the databse
prompt correct answer is (2,0)
select c.lic, c.position(12) from cartab c where lic like '1%';

help please >_<
msgolezAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

csachdevaCommented:
Usually, you may receive these errors when some of the objects are not initialized.

Cause of your error: An object, LOB, or other composite was referenced as a left hand side without having been initialized.  
 
Action: Initialize the composite with an appropriate constructor or whole-object assignment.  


Regards,
Chetan Sachdeva
0
ggridleyCommented:
The block that has:  

--initialize cur_l
     cur_l.x := null;
     cur_l.y := null;

needs to be:

--initialize cur_l
         cur_l := loctype(null, null); -- You need to initialize the cur_l type itself, not just the location and velocity;
0
ram_0218Commented:
You'r not manipulating the cur_l and just doing a select INTO. Atleast thats what your code shows.

In this case you dont need to instantiate the objects as they'll by default.
So just remove these two lines from your pgm.

  cur_l.x := null;
     cur_l.y := null;
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

msgolezAuthor Commented:
hmmm, i see. thanks for the reply guys. I'll test this out later tonight when I go back home (they blocked the ports here at work so i cant ssh to our oracle server).

Thanks!
0
actonwangCommented:
>>create or replace type body car is
member function position(t int) return loctype is
--function position returns position of the car at time t
     
     cur_l          loctype;          --car's current location
                                                     
You problem is the above line, change it to:
     cur_l          loctype := loctype(null,null);          --car's current location

you should be fine :)
Acton

0
actonwangCommented:
>>create or replace type body car is
>>member function position(t int) return loctype is
>>--function position returns position of the car at time t
>>     
 >>    cur_l          loctype;          --car's current location
                                                     
You problem is the above line, change it to:

     cur_l          loctype := loctype(null,null);          --car's current location

you should be fine :)
Acton
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
msgolezAuthor Commented:
thanks guys!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.