尝试在APEX上的某个页面中创建新行后,会出现以下错误:
ORA-02291:违反完整性约束(BD43015.SYS_C001194280) - 未找到父密钥ORA-06512:在“BD43015.INSERT_STUDENT”,第4行ORA-04088:执行触发器'BD43015.INSERT_STUDENT'ORA-06512时出错:在“SYS.WWV_DBMS_SQL”,第549行ORA-06512:在“APEX_040000.WWV_FLOW_DML”,第1121行ORA-22816:RETURNING子句不支持的功能 错误无法处理表V_ALLSTUDENTS行。 行
注意:我正在尝试使用此触发器:
create or replace trigger insert_student
instead of insert on v_allstudents
for each row
begin
insert into members values(:new.memberID, :new.name, :new.birth, :new.regist_date, :new.address, :new.sex, :new.phone);
insert into students values(:new.memberID, :new.guardian, :new.rank, :new.plan_name, :new.plan_value);
end;
/
这个观点:
create or replace view v_allstudents(memberID, name, birth, regist_date, address, sex, phone, guardian, rank, plan_name, plan_value) AS
select members.memberID, name, birth, regist_date, address, sex, phone, guardian, rank, plan_name, plan_value
from members, students
where members.memberID = students.memberID
order by members.name;
表成员:
drop table members cascade constraints;
create table members(
memberID number(10) not null,
name varchar2(30) not null,
birth date not null,
regist_date date not null,
address varchar2(50) not null,
sex char(1) not null CHECK (sex IN ('F', 'M')),
phone number(9),
primary key(memberID)
);
表学生:
drop table students cascade constraints;
create table students(
memberID number(10) not null,
guardian varchar2(30),
rank varchar2(20) not null,
plan_name varchar2 (30) not null,
plan_value number(10) not null,
primary key(memberID),
foreign key(memberID) references members(memberID)
);
EDIT FIX:我们遇到了与memberID
插入冲突的触发器。
答案 0 :(得分:0)
我可以成功地从SQLPLUS重现该问题。
以下声明有效。
declare
v_memberid number;
begin
insert into
v_allstudents(memberID, name, birth, regist_date, address, sex, phone, guardian, rank, plan_name, plan_value)
values
(1,'Neo',to_date('13-Jan-2009','dd-mon-yyyy'),to_date('13-Jan-2009','dd-mon-yyyy'),'My address','M',1234,'Trinity',1,'My Plan',2525)
end;
以下声明不起作用并抛出ORA-22816。
declare
v_memberid number;
begin
insert into
v_allstudents(memberID, name, birth, regist_date, address, sex, phone, guardian, rank, plan_name, plan_value)
values
(1,'Neo',to_date('13-Jan-2009','dd-mon-yyyy'),to_date('13-Jan-2009','dd-mon-yyyy'),'My address','M',1234,'Trinity',1,'My Plan',2525)
returning memberID into v_memberid;
end;
以下是Oracle文档中的错误说明。
对象类型列,LONG列,远程表,带子查询的INSERT,和INSTEAD OF触发器目前不支持RETURNING子句。
在这种情况下,Oracle Apex正在生成带有returns子句的Insert语句,或者您已在Oracle Apex中编写了带有返回子句的定制代码。
我建议使用Oracle apex表单取消触发器并将值插入这两个表中。