views:

241

answers:

3

I've declared the following types in my PL/SQL package:

TYPE t_simple_object IS RECORD (
   wert   NUMBER,
   gs     NUMBER,
   vl     NUMBER);

TYPE t_obj_table IS TABLE OF t_simple_object
  INDEX BY BINARY_INTEGER;

Then I declare a variable:

obj t_obj_table;

However, when I want to use the variable, I cannot initialize or extend it:

obj := t_obj_table ();

gives the following errror:

PLS-00222: no function with name 'T_OBJ_TABLE' exists in this scope

If I don't initialize it, I can't extend it to add some date as

obj.EXTEND();

gives another error:

PLS-00306: wrong number or types of arguments in call to 'EXTEND'

How can I make this work?

+2  A: 

You can not extend an assosiative array. Just assing values to it

declare
  TYPE t_simple_object IS RECORD (
    wert   NUMBER,
    gs     NUMBER,
    vl     NUMBER);

  TYPE t_obj_table IS TABLE OF t_simple_object INDEX BY BINARY_INTEGER;

  simple_object t_simple_object;
begin
  simple_object.wert := 1;
  simple_object.gs := 2;
  simple_object.vl := 3;
  obj(1) := simple_object;
end;
/
Robert Merkwürdigeliebe
+4  A: 

You don't extend a table indexed by "something", you can just use it...

DECLARE
   TYPE t_simple_object IS RECORD 
      ( wert   NUMBER
      , gs     NUMBER
      , vl     NUMBER
      ); 

   TYPE t_obj_table IS TABLE OF t_simple_object
   INDEX BY BINARY_INTEGER; 

   my_rec t_simple_object;
   obj t_obj_table; 
BEGIN
   my_rec.wert := 1;
   my_rec.gs := 1;
   my_rec.vl := 1;
   obj(1) := my_rec;
END;
/

To use the EXTEND syntax, this example should do it...

DECLARE
   TYPE t_simple_object IS RECORD 
      ( wert   NUMBER
      , gs     NUMBER
      , vl     NUMBER
      ); 

   TYPE t_obj_table IS TABLE OF t_simple_object; 

   my_rec t_simple_object;
   obj t_obj_table := t_obj_table(); 
BEGIN
   obj.EXTEND;
   my_rec.wert := 1;
   my_rec.gs := 1;
   my_rec.vl := 1;
   obj(1) := my_rec;
END;
/

Also see this link (Ask Tom)

Paul James
+3  A: 

If you don't want to use an associative array (aka index-by table) then leave out the "INDEX BY BINARY_INTEGER" clause. Your code then works OK:

declare 
    TYPE t_simple_object IS RECORD (
       wert   NUMBER,
       gs     NUMBER,
       vl     NUMBER);
    TYPE t_obj_table IS TABLE OF t_simple_object;
    obj t_obj_table;
begin  
    obj := t_obj_table ();
    obj.EXTEND();
end;
Tony Andrews