Если у вас есть авторы:
INSERT INTO Authors VALUES ( 'Alice', 'a@example.com', 'aaa' );
INSERT INTO Authors VALUES ( 'Beatrice', 'b@example.com', 'bbb' );
INSERT INTO Authors VALUES ( 'Carol', 'c@example.com', 'ccc' );
Затем вы можете заполнить PaperTable
(почему суффикс таблицы?) Следующим образом:
INSERT INTO PaperTable (
title,
language,
section,
authors
) VALUES (
'Paper 1',
'XY',
( SELECT REF(s) FROM SectionTable s WHERE section = 'Fiction' ),
AuthorRefType(
( SELECT REF(a) FROM Authors a WHERE name = 'Alice' ),
( SELECT REF(a) FROM Authors a WHERE name = 'Carol' )
)
);
INSERT INTO PaperTable (
title,
language,
section,
authors
)
SELECT 'Paper 2',
'YZ',
REF(s),
( SELECT CAST(
COLLECT(
REF( a )
) AS AuthorRefType
)
FROM Authors a
WHERE name IN ( 'Beatrice', 'Carol' )
)
FROM SectionTable s
WHERE section = 'Reference';
INSERT INTO PaperTable (
title,
language,
section,
authors
) VALUES (
'Paper 3',
'XZ',
NULL,
NULL
);
, а затем:
SELECT p.title,
p.language,
DEREF( p.section ).section AS section,
DEREF( a.COLUMN_VALUE ).name AS name,
DEREF( a.COLUMN_VALUE ).email AS email,
DEREF( a.COLUMN_VALUE ).institute AS institute
FROM PaperTable p
LEFT OUTER JOIN TABLE( p.Authors ) a
ON ( 1 = 1)
выходы:
TITLE | LANGUAGE | SECTION | NAME | EMAIL | INSTITUTE
:------ | :------- | :-------- | :------- | :------------ | :--------
Paper 1 | XY | Fiction | Alice | a@example.com | aaa
Paper 1 | XY | Fiction | Carol | c@example.com | ccc
Paper 2 | YZ | Reference | Beatrice | b@example.com | bbb
Paper 2 | YZ | Reference | Carol | c@example.com | ccc
Paper 3 | XZ | <em>null</em> | <em>null</em> | <em>null</em> | <em>null</em>
дБ <> скрипка здесь