How to manipulate objects with inheritance in sql (oracle)?

242 Views Asked by At

Supposing that i have that hierarchy, how can i manipulate (add, edit) an agent or a client ?

CREATE TYPE TPRENOM AS varray(3) OF VARCHAR2(20);

CREATE TYPE tadr as object(
  cp int  not null,
  state varchar2(20),
  city varchar2(20),
  street varchar2(20),
  doorNum int
);

create type tperson as object(
  fname varchar2(20),
  lname tprenom,
  adress tadr,
  phoneNum varchar2(10),
  email varchar2(50)
)not final;

create type tutilisateur under tperson(
  username varchar2(20),
  password varchar2(20)
);

create table agent(
  id_ag int not null,
  infos tutilisateur not null
  , CONSTRAINT agent_pk PRIMARY KEY 
    (
      ID_ag
    )
  enable
);

create table client(
id_cl int  not null,
infos tperson  not null,
num_chec varchar2(30) not null,
 CONSTRAINT client_pk PRIMARY KEY 
  (
    ID_cl 
  )
  enable
);

I've tried these, but it didn't work :

insert into agent values(1, tutilisateur( tperson( 'name', tprenom('bilel', 
'dani','lastname3'), tadr(3,'state', 'miliana', 'hammama', 20), 
'2140547854', '[email protected]'), 'username', 'password'));

insert into client values(0, tperson('name', tprenom('bilel', 'dani', 
'lastname3'), tadr(3,'state2','miliana','hammama',20)),'123456789');

That's the error displaying when excecuting the sql above :

Erreur SQL : ORA-02315: incorrect number of arguments for default constructor

  1. 00000 - "incorrect number of arguments for default constructor"

*Cause: The number of arguments specified for the default constructor doesn't match the number of attributes of the object type.

*Action: Specify the correct number of arguments for the default constructor and retry the operation.

I'm i doing inheritance wrong ?

Thanks for your response

1

There are 1 best solutions below

0
BHA Bilel On

Okay i found the solution, i can't beleive how easy it was,that's how to insert into agent table :

insert into agent 
values(1,tutilisateur('name',tprenom('bilel','dani','lastname3'),tadr(3,'ain 
delfa','miliana','hammama',20),'2140547854','[email protected]','username','password'));

That's how to insert into client table :

insert into client 
values(0,tperson('name',tprenom('bilel','dani','lastname3'),tadr(3,'ain 
delfa','miliana','hammama',20),'11225','[email protected]'),'123456789');