Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database 将记录插入数据库Oracle SQLPLUS时出错_Database_Oracle_Sql Insert_Sqlplus_Sql View - Fatal编程技术网

Database 将记录插入数据库Oracle SQLPLUS时出错

Database 将记录插入数据库Oracle SQLPLUS时出错,database,oracle,sql-insert,sqlplus,sql-view,Database,Oracle,Sql Insert,Sqlplus,Sql View,我是新手,所以这可能很傻,但是 我创建了3个表: create table faculty (id_faculty number(2) Primary Key, //id , 2 digits, primary key faculty_name varchar2(30) constraint f_name Not Null, // name, up to 30 symbols, not null dean varchar2(20), // dean, up to 20 symbols

我是新手,所以这可能很傻,但是

我创建了3个表:

  create table faculty (id_faculty number(2) Primary Key, //id , 2 digits, primary key
  faculty_name varchar2(30) constraint f_name Not Null, // name, up to 30 symbols, not null
  dean varchar2(20), // dean, up to 20 symbols
  telephone varchar2(8)); //number, up to 8 symbols

create or replace view stud_stip AS
 Select f.faculty_name, student_surname, student_name, s.course_year,
 m.stipend, m.payout_date
 from
 faculty f inner join student s on f.id_faculty=s.faculty_id
 inner join money m on m.student_id=s.id_student
 where
 m.payout_date = ( select distinct max(payout_date)
 from money
 where money.student_id=money.student_id)
 with check option;
insert into stud_stip values ('Partikas tehnologiju', 'Lapa', 'Jana', 2, 120, '03.12.1998');
ORA-01779: cannot modify a column which maps to a non key-preserved table

然后我想向视图添加信息:

  create table faculty (id_faculty number(2) Primary Key, //id , 2 digits, primary key
  faculty_name varchar2(30) constraint f_name Not Null, // name, up to 30 symbols, not null
  dean varchar2(20), // dean, up to 20 symbols
  telephone varchar2(8)); //number, up to 8 symbols

create or replace view stud_stip AS
 Select f.faculty_name, student_surname, student_name, s.course_year,
 m.stipend, m.payout_date
 from
 faculty f inner join student s on f.id_faculty=s.faculty_id
 inner join money m on m.student_id=s.id_student
 where
 m.payout_date = ( select distinct max(payout_date)
 from money
 where money.student_id=money.student_id)
 with check option;
insert into stud_stip values ('Partikas tehnologiju', 'Lapa', 'Jana', 2, 120, '03.12.1998');
ORA-01779: cannot modify a column which maps to a non key-preserved table
这是我得到的错误:

  create table faculty (id_faculty number(2) Primary Key, //id , 2 digits, primary key
  faculty_name varchar2(30) constraint f_name Not Null, // name, up to 30 symbols, not null
  dean varchar2(20), // dean, up to 20 symbols
  telephone varchar2(8)); //number, up to 8 symbols

create or replace view stud_stip AS
 Select f.faculty_name, student_surname, student_name, s.course_year,
 m.stipend, m.payout_date
 from
 faculty f inner join student s on f.id_faculty=s.faculty_id
 inner join money m on m.student_id=s.id_student
 where
 m.payout_date = ( select distinct max(payout_date)
 from money
 where money.student_id=money.student_id)
 with check option;
insert into stud_stip values ('Partikas tehnologiju', 'Lapa', 'Jana', 2, 120, '03.12.1998');
ORA-01779: cannot modify a column which maps to a non key-preserved table
我已经在互联网上搜索过了,没有解决我的错误,请不要给我发送关于这个问题的其他主题,因为我可能已经读过了


我将非常感谢你的回答。提前谢谢。

方法是在视图上创建一个而不是触发器,该触发器将依次将行插入适当的表中

由于所有
ID
列都是主键,并且您没有解释如何填充它们,因此我将使用一个序列,以相同的方式而不是触发器来完成

SQL> create sequence seqs;

Sequence created.

SQL> create or replace trigger trg_stud_stip
  2    instead of insert on stud_stip
  3    for each row
  4  begin
  5    insert into faculty (id_faculty, faculty_name)
  6      values (seqs.nextval, :new.faculty_name);
  7
  8    insert into student (id_student, student_name, student_surname, course_year)
  9      values (seqs.nextval, :new.student_name, :new.student_surname, :new.course_year);
 10
 11    insert into money (id_payout, stipend, payout_date)
 12      values (seqs.nextval, :new.stipend, :new.payout_date);
 13  end;
 14  /

Trigger created.
测试(不要在
DATE
datatype列中插入字符串!):


它起作用了。既然您已经知道了该如何操作,请在必要时对其进行改进。

视图只是一个存储的查询,其名称用于引用它。它没有数据。您不会将数据添加到视图中,而是将其添加到基础表中。