!Good!
I am doing an exercise on Relational Objects in Database. The truth is that I am a bit lost, and I need to insert some data in a table that I have created in the following way:
CREATE TABLE empleados OF Empleado(
idEmpleado PRIMARY KEY);
And the object type is this:
CREATE OR REPLACE TYPE Empleado AS OBJECT(
idEmpleado NUMBER,
nombre VARCHAR(20),
apellidos VARCHAR(20),
salario NUMBER,
vencargado REF Encargado,
MAP MEMBER FUNCTION ordenarID return NUMBER,
MEMBER FUNCTION encargadoEmpleado return Encargado);
CREATE OR REPLACE TYPE BODY Empleado
AS
MAP MEMBER FUNCTION ordenarID return NUMBER
IS
BEGIN
RETURN idEmpleado;
END;
END;
Where the attribute of vencargado
comes from this other object type:
CREATE TYPE Encargado AS OBJECT(
idEncargado NUMBER,
nombre VARCHAR(20),
apellidos VARCHAR(20),
cargo VARCHAR(20),
MAP MEMBER FUNCTION ordenarID return NUMBER,
MEMBER FUNCTION empleadosCargo return NUMBER);
CREATE TYPE BODY Encargado
AS
MAP MEMBER FUNCTION ordenarID return NUMBER
IS
BEGIN
RETURN idEncargado;
END;
END;
I have tried to add some data to the employees table and this error has occurred to me, and I don't know how to enter the values:
inconsistent data types: expected REF got NUMBER
I have added them like this:
INSERT INTO empleados VALUES ( Empleado(1,'Juan','Rodriguez',1600,1));
If someone can guide me, it would be very helpful. Thanks.
!Good!
I already resolved it.
The problem was in the creation of the table
Empleados
since it did not refer to the object ofEmpleado
. To fix it, create it as follows:And so it allows inserting data without problems, or at least, it has not given me any problem.
I hope it will serve as a reference for other users :)