Reputation: 13
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
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
Reputation: 231891
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