Reputation: 31
CREATE TYPE empresa_type AS OBJECT (
CNPJ INTEGER,
nome_fantasia VARCHAR2(30),
pais VARCHAR2(25),
fundacao DATE
)
CREATE TYPE funcionario_type AS OBJECT (
CPF INTEGER,
nome VARCHAR2(30),
sexo CHAR(1),
nasc DATE,
empresa REF empresa_type
)
CREATE TABLE empresa_tab OF empresa_type (PRIMARY KEY(CNPJ))
CREATE TABLE funcionario_tab OF funcionario_type (PRIMARY KEY(CPF), FOREIGN KEY(empresa) REFERENCES empresa_tab)
report error: ORA-00932: inconsistent datatypes: expected CHAR got REF MY_WKSP.EMPRESA_TYPE
Upvotes: 1
Views: 391
Reputation: 167982
You want to create the table and then add a SCOPE
to the reference (rather than trying to define it as a foreign key, because it is not):
CREATE TABLE funcionario_tab OF funcionario_type (
PRIMARY KEY(CPF)
);
ALTER TABLE funcionario_tab ADD SCOPE FOR ( empresa ) IS empresa_tab;
db<>fiddle here
Upvotes: 0