如何在ORDBMS中将数据插入到彼此具有引用的表中?

时间:2016-09-03 01:54:27

标签: oracle database-design oracle-sqldeveloper oracle12c object-relational-model

CREATE TYPE Dept_t1
/
CREATE TYPE Emp_t1 AS OBJECT(
 eno number(4), 
 ename varchar2(15), 
 edept ref dept_t1, 
 salary number(8,2));
/
CREATE TYPE Dept_t1 AS OBJECT(
 dno number(2), 
 dname varchar2(12), 
 mgr ref emp_t1);
/
CREATE TYPE Proj_t1 AS OBJECT(
 pno number(4),
 pname varchar2(15), 
 pdept ref dept_t1, 
 budget number(10,2));
/

CREATE TABLE Emp1 OF Emp_t1(
 eno PRIMARY KEY
);
CREATE TABLE Dept1 OF Dept_t1(
 dno PRIMARY KEY
);
CREATE TABLE Proj1 OF Proj_t1(
 pno PRIMARY KEY
);
ALTER TABLE Emp1 MODIFY (edept REFERENCES Dept1);
ALTER TABLE Dept1 MODIFY (mgr REFERENCES Emp1);
ALTER TABLE Proj1 MODIFY (pdept REFERENCES dept1);
INSERT INTO Emp1 VALUES(1,'A',(SELECT REF(d) FROM Dept1 d where d.dno=11),30)
/
INSERT INTO Emp1 VALUES(2,'B',(SELECT REF(d) FROM Dept1 d where d.dno=12),50)
/
INSERT INTO Dept1 VALUES(11,'D1',(SELECT REF(e) FROM Emp1 e where e.eno=1))
/
INSERT INTO Dept1 VALUES(12,'D2',(SELECT REF(e) FROM Emp1 e where e.eno=2))
/
INSERT INTO Proj1 VALUES(111,'P1',(SELECT REF(e) FROM Dept1 e where e.dno=11),25)
/
INSERT INTO Proj1 VALUES(112,'P2',(SELECT REF(e) FROM Dept1 e where   e.dno=12),35)
/

当我尝试执行以下查询时,   SELECT p.pname,p.pdept.dno FROM Proj1 p WHERE p.budget> 45

p.pdept.dno列为空。如何解决这个问题?我已经添加了所有值。但不确定为什么会显示空值。我是对象关系数据库管理系统的新手。所以我需要你们所有人的帮助。

Dept1表格图像是这样的。 enter image description here

0 个答案:

没有答案