Reputation: 116
SQL> create or replace type societe
as object (nom_societe varchar2(20),ville_societe varchar2(20));
/
create or replace type produit as object(
nom varchar2(20),
poids number(9),
couleur varchar2(20),
composants varchar2(2));
/
SQL> insert into commande(NUMERO,DATE_SOUMISSION,DATE_ENVOI,SOCIETE,PRODUIT) values(
2 1,to_date('2013/03/11','yyyy/mm/dd'),to_date('2014/05/12','yyyy/mm/dd'),
3 societe('BME','FES'),produit('prod1',12,'noir','aluminium'));
insert into commande(NUMERO,DATE_SOUMISSION,DATE_ENVOI,SOCIETE,PRODUIT) values(
*
ERROR at line 1:
ORA-22814: attribute or element value is larger than specified in type
SQL> create table commande(
2 numero number(9),
3 date_soumission date,
4 date_envoi date,
5 societe societe,
6 produit produit);
Upvotes: 1
Views: 934
Reputation: 49112
composants varchar2(2)
'aluminium'
Clearly the fourth element 'aluminium' you are trying to insert into composants attribute, is larger than 2 characters/bytes as the size of data type is VARCHAR2(2)
. Increase the size of composants
so that it can store the element.
CREATE OR REPLACE TYPE societe AS OBJECT (
nom_societe VARCHAR2(20),
ville_societe VARCHAR2(20)
)
/
CREATE OR REPLACE TYPE produit AS OBJECT (
nom VARCHAR2(20),
poids NUMBER(9),
couleur VARCHAR2(20),
composants VARCHAR2(20)
)
/
CREATE TABLE commande (
numero NUMBER(9),
date_soumission DATE,
date_envoi DATE,
society societe,
product produit
);
Now you can insert in following way:
INSERT INTO commande (
numero,
date_soumission,
date_envoi,
society,
product
) VALUES (
1,
TO_DATE('2013/03/11', 'yyyy/mm/dd'),
TO_DATE('2014/05/12', 'yyyy/mm/dd'),
societe('BME', 'FES'),
produit('prod1', 12, 'noir', 'aluminium')
);
You can check the data inserted:
SELECT * FROM commande;
NUMERO DATE_SOU DATE_ENV SOCIETY(NOM_SOCIETE, PRODUCT(NOM, POIDS, COULEUR, COMPOSANTS)
------ -------- -------- --------------------- -----------------------------------------
1 11-03-13 12-05-14 SOCIETE('BME', 'FES') PRODUIT('prod1', 12, 'noir', 'aluminium')
Upvotes: 2