ORA-00907:在Oracle APEX上执行INSERT INTO时,缺少右括号错误



我正在使用对象关系oracle数据库(oracle Apex(创建一个包含员工、客户、书籍、副本和租赁的数据库。我有一张多态性的人表,既接受员工也接受客户。我得到了一个错误,即:;ORA-00907:缺少右括号";当尝试将客户端插入人员表时。我真的不知道为什么。有人能帮我吗?错误发生在以下插入中:

insert into pessoa_tb_or values(
cliente_typ(7, 'CLIENTE JUNIOR', 1, to_date('01/01/2020'), telefones_typ('9999-9999', '9999-8888'), 
locacoes_nt_typ((1, to_date('01/01/2022'), (select ref(e) from exemplar_tb_or e where cod_exemplar = 1) ), (2, to_date('01/05/2022'), (select ref(e) from exemplar_tb_or e where cod_exemplar = 2) ) )))

这是我的完整代码和数据库需求规范(葡萄牙语(。数据库规范此分配的规则为:架构必须包含对象类型、对象表、层次结构、REF数据类型、嵌套表、VARRAY和完整性约束。在每个对象表中至少插入5个对象。

`

create type livro_typ as object(
cod_livro int,
titulo varchar2(50),
autor varchar2(50)
)
create type exemplar_typ as object(
cod_exemplar int,
data_compra date,
livro ref livro_typ
)
create type pessoa_typ as object(
cpf int,
nome varchar2(50)
)not final
create type funcionario_typ under pessoa_typ(
cod_funcionario int,
turno varchar2(20)
)
create type telefones_typ as varray(3) of varchar2(20)

create type locacao_typ as object(
cod_locacao int,
data_aluguel date,
exemplar_livro ref exemplar_typ
)
create type locacoes_nt_typ as table of locacao_typ
create type cliente_typ under pessoa_typ(
cod_cliente int,
data_cadastro date,
telefones telefones_typ,
alugueis locacoes_nt_typ
)
create table pessoa_tb_or of pessoa_typ(
primary key(cpf),
nome not null
)
create table livro_tb_or of livro_typ(
primary key(cod_livro),
titulo not null,
autor not null
)
create table exemplar_tb_or of exemplar_typ(
primary key(cod_exemplar),
data_compra not null,
livro not null
)

insert into pessoa_tb_or values(pessoa_typ(1, 'PESSOA JOAO'))
insert into pessoa_tb_or values(funcionario_typ(2, 'FUNCIONARIO PEDRO', 1, 'MANHA'))
insert into pessoa_tb_or values(funcionario_typ(3, 'FUNCIONARIO HENRIQUE', 2, 'MANHA'))
insert into pessoa_tb_or values(funcionario_typ(4, 'FUNCIONARIO LAURA', 3, 'TARDE'))
insert into pessoa_tb_or values(funcionario_typ(5, 'FUNCIONARIO LUIZA', 4, 'TARDE'))
insert into pessoa_tb_or values(funcionario_typ(6, 'FUNCIONARIO LETICIA', 5, 'NOITE'))
insert into livro_tb_or values(livro_typ(1, 'COMPUTACAO PARA LEIGOS', 'HENRIQUE FEITOSA'))
insert into livro_tb_or values(livro_typ(2, 'BANCO DE DADOS PARA LEIGOS', 'HENRIQUE FEITOSA'))
insert into livro_tb_or values(livro_typ(3, 'APRENDIZAGEM DE MAQUINA PARA LEIGOS', 'MARIA BRAGA'))
insert into livro_tb_or values(livro_typ(4, 'MATEMATICA PARA LEIGOS', 'MARIA BRAGA'))
insert into livro_tb_or values(livro_typ(5, 'FISICA PARA LEIGOS', 'FERNANDO LIMA'))
insert into exemplar_tb_or values(exemplar_typ(1, to_date('01/01/2020'), (select ref(l) from livro_tb_or l where cod_livro = 1) ))
insert into exemplar_tb_or values(exemplar_typ(2, to_date('01/01/2021'), (select ref(l) from livro_tb_or l where cod_livro = 2) ))
insert into exemplar_tb_or values(exemplar_typ(3, to_date('01/01/2022'), (select ref(l) from livro_tb_or l where cod_livro = 3) ))
insert into exemplar_tb_or values(exemplar_typ(4, to_date('01/01/2019'), (select ref(l) from livro_tb_or l where cod_livro = 4) ))
insert into exemplar_tb_or values(exemplar_typ(5, to_date('01/01/2019'), (select ref(l) from livro_tb_or l where cod_livro = 5) ))


insert into pessoa_tb_or values(
cliente_typ(7, 'CLIENTE JUNIOR', 1, to_date('01/01/2020'), telefones_typ('9999-9999', '9999-8888'), 
locacoes_nt_typ((1, to_date('01/01/2022'), (select ref(e) from exemplar_tb_or e where cod_exemplar = 1) ), (2, to_date('01/05/2022'), (select ref(e) from exemplar_tb_or e where cod_exemplar = 2) ) )
))

`该问题仅出现在最后一次插入中。

我已经尝试过只为客户端创建一个表,但仍然会出现同样的错误。我真的很感激任何帮助!

您有一个嵌套的表类型,但缺少其元素的对象类型:

insert into pessoa_tb_or values(
cliente_typ(7, 'CLIENTE JUNIOR', 1, to_date('01/01/2020'), telefones_typ('9999-9999', '9999-8888'), 
locacoes_nt_typ(
locacao_typ(1, to_date('01/01/2022'), (select ref(e) from exemplar_tb_or e where cod_exemplar = 1)),
locacao_typ(2, to_date('01/05/2022'), (select ref(e) from exemplar_tb_or e where cod_exemplar = 2))
)))

小提琴


顺便说一句,to_date('01/01/2022')依赖于会话NLS设置。最好用to_date('01/01/2022', 'DD/MM/YYYY')指定格式,或者更简单地用date '2022-01-01':使用日期文字

insert into pessoa_tb_or values(
cliente_typ(7, 'CLIENTE JUNIOR', 1, date '2020-01-01', telefones_typ('9999-9999', '9999-8888'), 
locacoes_nt_typ(
locacao_typ(1, date '2022-01-01', (select ref(e) from exemplar_tb_or e where cod_exemplar = 1)),
locacao_typ(2, date '2022-05-01', (select ref(e) from exemplar_tb_or e where cod_exemplar = 2))
)))

小提琴

相关内容

最新更新