我在我的数据库中有这两个表,DEPT1和EMP1对雇主部门和雇主列表有所帮助,表EMP1包含一个名为refdept的外键。 我的问题是我可以将数据插入DEPT1但不能插入EMP1,这是我得到的异常:
instanciation de la connexion connexion1
nov. 17, 2014 7:54:12 PM tp.dao.DeptDAO create
Infos: create new instance
nov. 17, 2014 7:54:13 PM tp.dao.DeptDAO create
Infos: New instance is created.
nov. 17, 2014 7:54:13 PM tp.dao.DeptDAO create
Infos: Return Result == true
nov. 17, 2014 7:54:13 PM tp.dao.EmpDAO create
Infos: create new instance
nov. 17, 2014 7:54:13 PM tp.dao.EmpDAO create
Grave: ORA-02291: integrity constraint (BASE.FK_DEPT) violated - parent key not found
java.sql.SQLIntegrityConstraintViolationException: ORA-02291: integrity constraint (base.FK_DEPT) violated - parent key not found
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)
l'employéEMP5est ajouté à cet département
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:837)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:445)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:523)
at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:204)
at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1007)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1315)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3576)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3657)
at oracle.jdbc.driver.OracleCallableStatement.executeUpdate(OracleCallableStatement.java:4739)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1350)
at tp.dao.EmpDAO.create(EmpDAO.java:48)
at tp.TP.main(TP2.java:84)
nov. 17, 2014 7:54:13 PM tp.dao.EmpDAO create
Infos: Return Result == false
nov. 17, 2014 7:54:13 PM tp.dao.EmpDAO create
Infos: Return Result == false
我试过了:
insert into base.EMP1(ide,nome,rue,ville,refdept) values (7,"EMP5","agadir","dddd",(select idd from base.DEPT1 where nomd ='Math'));
我收到此错误:
Error code 984, SQL state 42000: ORA-00984: column not allowed here
任何帮助请求和感谢:(
答案 0 :(得分:2)
ORA-02291:违反了完整性约束(BASE.FK_DEPT) - 找不到父密钥
DEPT1中没有这样的值,请先检查一下。
插入base.EMP1(ide,nome,rue,ville,refdept)值(7,“EMP5”,“agadir”,“dddd”,(从base.DEPT1中选择idd,其中nomd ='Math')) ;
试试这个:
insert into base.EMP1(ide,nome,rue,ville,refdept)
select 7,'EMP5','agadir','dddd', idd from base.DEPT1 where nomd ='Math';
答案 1 :(得分:1)
看起来您在DEPT1中没有 idd 列
尝试:
insert into base.EMP1(ide,nome,rue,ville,refdept) values (7,"EMP5","agadir","dddd",(select ido from base.DEPT1 where nomd ='Math'));
答案 2 :(得分:1)
我认为你应该这样试试:
insert into base.EMP1(ide,nome,rue,ville,refdept) values (7,'EMP5','agadir','dddd',
(select idd from base.DEPT1 where nomd ='Math'));