Basically, I want to create references to records, one record type is a supertype of the other. I am a bit confused over it.
Here are my types:
CREATE OR REPLACE TYPE module_t AS OBJECT (
moduleCode# char(4),
moduleName char(10)
) NOT FINAL;
/
CREATE OR REPLACE TYPE specialised_module_t under module_t (
someSpecialAttribute char(10)
);
/
CREATE OR REPLACE TYPE course_t AS OBJECT (
courseCode# char(4),
module1 REF module_t,
module2 REF specialised_module_t
);
/
Here are my tables:
CREATE TABLE module_tab OF module_t(
moduleCode# PRIMARY KEY NOT NULL
);
CREATE TABLE course_tab OF course_t(
courseCode# PRIMARY KEY NOT NULL,
scope for (module1) is module_tab,
scope for (module2) is module_tab
);
I insert a record into the module table consisting of a standard module:
insert into module_tab values(
'm001', 'physics'
);
I insert a record into the module table consisting of a specialised module:
insert into module_tab
values( specialised_module_t(
'm002',
'physics',
'special'
)
);
Here is the tricky bit:
I want to create a course record in the course table. In this record, the module1
attribute needs to reference module m001
(the first module record) and the module2
attribute needs to reference module m002
I have thought maybe it would look something like this:
INSERT into course_tab VALUES(
'c001',
SELECT REF(c) FROM module_tab c WHERE c.moduleCode# = 'm001',
SELECT REF(c) FROM module_tab c WHERE c.moduleCode# = 'm002'
)
This just doesn't work :(
Here is the error message:
ERROR at line 3:
ORA-00936: missing expression
Obviously my syntax is wrong, but I don't know how to correct it :/
I have spent ages on this and I can't figure it out :(
Help will be much appreciated :D
Thanks
UPDATE:
With help from @a_horse_with_no_name my new code is:
INSERT into course_tab VALUES(
'c001',
(SELECT REF(c) FROM module_tab c WHERE c.moduleCode# = 'm001'),
(SELECT treat(REF(c) as ref specialised_module_t) FROM module_tab c WHERE treat(values(c) as moduleCode).person# = 'm002')
);
But now I get the error:
ERROR at line 4:
ORA-00936: missing expression
please help, thanks :)