Bob darkside
Bob darkside

Reputation: 13

Constructor for nested table with oracle

I want to create a constructor for the 2 types below. Here's the code:

create or replace type toys_t as table of varchar2(40);

create or replace type kid_t as object (
      name varchar2(10), 
      toys toys_t,
      constructor function kid_t (name varchar2) return self as result);

create table kid of kid_t nested table toys store as table_toys;

Is there a way of creating a user-defined constructor for the nested table type toys_t or is it only supported for TYPEs created using the as object syntax?

Thanks

Bob

Upvotes: 1

Views: 1477

Answers (2)

APC
APC

Reputation: 146349

No, we cannot declare user-defined constructors for types like your toys_t table. Collection types (nested tables or varrays) only have default constructors. All we can do is specify a default which is applied when we instantiate a collection without any arguments. Find out more.

Upvotes: 2

Justin Cave
Justin Cave

Reputation: 231881

There is automatically a constructor for collections like toys_t. Just use the name of the collection

SQL> insert into kid values( 'Bobby', toys_t( 'Bike', 'Ball', 'Legos' ));

1 row created.

The toys_t constructor can take 0, 1, or many parameters.

Upvotes: 2

Related Questions