Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Tables of Records in PL/SQL

Tags:

oracle

plsql

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?

like image 629
Thorsten Avatar asked Oct 22 '09 12:10

Thorsten


People also ask

What is table based records in PL SQL?

A table-based record, or table record, is a record whose structure (set of columns) is drawn from the structure (list of columns) of a table. Each field in the record corresponds to and has the same name as a column in the table.

How do I get a list of tables in PL SQL?

SELECT TABLE_NAME FROM USER_TABLES will provide you with listing of tables in a particular schema. SELECT TABLE_NAME, OWNER FROM ALL_TABLES will provide you with listing of all tables for all schemas in the DB for which you have at least select privilege.

How do you insert a record into a table in PL SQL?

Data Insertion In PL/SQL, we can insert the data into any table using the SQL command INSERT INTO. This command will take the table name, table column and column values as the input and insert the value in the base table.

What is the difference between PL SQL table and record?

Table columns relate to the fields. Records are made up of a collection of fields that are similar to the columns in a row. You can declare a PL/SQL record that resembles a row in a database table without listing all the columns using the % ROWTYPE attribute.


1 Answers

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)

like image 52
PaulJ Avatar answered Oct 13 '22 05:10

PaulJ