INSERT ALL错误ORA-02291完整性约束,但引用了PK

时间:2019-07-12 17:58:58

标签: oracle oracle-livesql

我正在为一个班级创建一个基本的销售和库存数据库。

我已经成功创建了我想要PK和FK放置的必要表。

我现在遇到的问题是当我尝试在雇员表中执行多次插入时。

以下是到目前为止已创建并插入的内容:

self

当我运行INSERT ALL INTO employee语句时,出现此错误:

const MyComponent = () => { return ( <SafeAreaView> <Text>MyComponent</Text> </SafeAreaView> ) } MyComponent.navigationOptions = ({ /*navigation*/ }) => { return { header: null } }

1 个答案:

答案 0 :(得分:1)

插入到employees表中的邮政编码值与您在位置表中创建的邮政编码值不匹配,因此该错误是有效的并且是预期的。

要么更改员工的邮政编码以匹配您已经拥有的位置,要么更有可能-由于您已经将这些邮政编码用于客户-为尝试使用的邮政编码添加新的位置:

INSERT ALL  
  INTO  location (zipcode, city) VALUES (77453, 'Lane City')  
  INTO  location (zipcode, city) VALUES (77096, 'Houston')  
  INTO  location (zipcode, city) VALUES (77231, 'Houston')  
  INTO  location (zipcode, city) VALUES (78113, 'Falls City')  
  INTO  location (zipcode, city) VALUES (79448, 'Richland')  
SELECT * FROM dual
;

5 rows inserted.

INSERT ALL  
  INTO employees (employeeid, firstname, lastname, street, state, zipcode, datehired, phonenum, salaryhr) VALUES (1, 'Jason', 'Wayne', '103 Brown St', 'TX', 77453, '14-may-13', 2814441304, 13)  
  INTO employees (employeeid, firstname, lastname, street, state, zipcode, datehired, phonenum, salaryhr) VALUES (2, 'Jacob', 'Dutch', '14 Yawn Rd', 'TX', 77096, '12-july-11', 8325472222, 10)  
  INTO employees (employeeid, firstname, lastname, street, state, zipcode, datehired, phonenum, salaryhr) VALUES (3, 'Susan', 'Anthony', '1 Patronas Ln', 'TX', 77231, '08-jan-17', 2819993547, 9)  
  INTO employees (employeeid, firstname, lastname, street, state, zipcode, datehired, phonenum, salaryhr) VALUES (4, 'David', 'Lane', '888 Madrid Blvd', 'TX', 78113, '27-dec-18', 8321119876, 8)  
  INTO employees (employeeid, firstname, lastname, street, state, zipcode, datehired, phonenum, salaryhr) VALUES (5, 'Anthony', 'Barnard', '21 Adiom Cl', 'TX', 79448, '13-nov-17', 2814558008, 10)  
SELECT * FROM dual
;

5 rows inserted.

db<>fiddle