Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2828
  • Last Modified:

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 >_<
0
msgolez
Asked:
msgolez
1 Solution
 
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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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
 
msgolezAuthor Commented:
thanks guys!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now