我在 oracle 的嵌套表中插入时遇到问题
这些是相关的类型和表格;
create type movies_type as Table of ref movie_type;
create type actor_type under person_type
(
starring movies_type
) Final;
create table actor of actor_type
NESTED TABLE starring STORE AS starring_nt;
这就是我尝试插入的方式
insert into actor values
(actor_type(29,'Carrie','Fisher',TO_DATE('21/10/1956', 'DD/MM/YY'),TO_DATE('27/12/2016', 'DD/MM/YY'),'USA', movies_type(select ref(m) from movie m where movie_id in (7, 8, 9))));
这不起作用,它给
SQL Error: ORA-00936: missing expression
这不是很有帮助。
我还尝试将 select 语句嵌套在括号中,因为我认为这可能是语法错误
insert into actor values
(actor_type(29,'Carrie','Fisher',TO_DATE('21/10/1956', 'DD/MM/YY'),TO_DATE('27/12/2016', 'DD/MM/YY'),'USA', movies_type((select ref(m) from movie m where movie_id in (7, 8, 9)))));
但它说
SQL ERROR ORA-01427: single-row subquery returns more than one row
所以我把它改成了这个
insert into actor values
(actor_type(29,'Carrie','Fisher',TO_DATE('21/10/1956', 'DD/MM/YY'),TO_DATE('27/12/2016', 'DD/MM/YY'),'USA', movies_type((select ref(m) from movie m where movie_id=7))));
这有效,但这不是我想要的,因为它不允许我有多个值
movies_type
我不明白问题到底是什么,错误消息没有帮助
为什么它说缺少表达?
为什么在第二种情况下它给单行子查询返回不止一行?
非常感谢您。
更新:这里是类型 movie_type 和表电影:
create type movie_type as Object
(
MOVIE_ID NUMBER(15),
TITLE VARCHAR(50) ,
GENRE VARCHAR(30),
RELEASE_DATE DATE,
RUNNING_TIME NUMBER,
BUDGET NUMBER
) Final;
表创建:
create table MOVIE of movie_type;
ALTER TABLE MOVIE
ADD CONSTRAINT PK_MOVIE_ID PRIMARY KEY (MOVIE_ID);
ALTER TABLE MOVIE modify TITLE not null;
电影中的相关插入:
INSERT INTO MOVIE (MOVIE_ID, TITLE, GENDER, RELEASE_DATE, RUNNING_TIME, BUDGET) VALUES (7,'Star Wars','epic space opera',TO_DATE('25/05/1977', 'DD/MM/YY'),121,11000000);
INSERT INTO MOVIE (MOVIE_ID, TITLE, GENDER, RELEASE_DATE, RUNNING_TIME, BUDGET) VALUES (8,'The Empire Strikes Back','epic space opera',TO_DATE('17/05/1980', 'DD/MM/YY'),124,18000000);
INSERT INTO MOVIE (MOVIE_ID, TITLE, GENDER, RELEASE_DATE, RUNNING_TIME, BUDGET) VALUES (9,'Return of the Jedi','epic space opera',TO_DATE('25/05/1983', 'DD/MM/YY'),132,32500000);