Home » SQL & PL/SQL » SQL & PL/SQL » Error performing insert (Oracle Sql Developed)
Error performing insert [message #678712] Thu, 02 January 2020 10:51 Go to next message
Messages: 1
Registered: January 2020
Junior Member
I have problems inserting into a table called accounts, however I have relationship with the company table.

In the company table I have the following fields:

Company_ID Company_Name Subscription_State.

255 AMG Ltda 08522255

Already in the table of accounts I have the following fields:

Account_ID Id_Company Value Enrollment_Estadual Year_Mes Year_Mes_Account ICMS TOTAL_Collected

However to perform the insert I have to check if the state registration that I am inserted exists in the company table, if it exists I insert, if not returns the insertion error. I do not know if there is a possibility to do in select the ones that do not exist do not insert and in the end show those state registrations that are not linked with any company in the database. How could the error I am getting and this validation be treated?

INSERT INTO Accounts (
State registration,
year month,
'25300.38 ',
(SELECT emp_company FROM COMPANY emp where emp.Subscription_State = '08522255'),
'38011.71 ',
(38011.71 ');

ORA-02291: Integrity constraint (U_FUNDAP.FK_EMPRESA_FINANCING) violated - parent key not found
Re: Error performing insert [message #678713 is a reply to message #678712] Thu, 02 January 2020 12:19 Go to previous message
Michel Cadot
Messages: 68264
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Welcome to the forum.
Please read the OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Also always post your Oracle version, with 4 decimals, as solution depends on it.

ORA-02291: integrity constraint (%s.%s) violated - parent key not found
 *Cause: A foreign key value has no matching primary key value.
 *Action: Delete the foreign key or add a matching primary key.
With any SQL or PL/SQL question, please, Post a working Test case: create statements for all objects so that we will be able work to reproduce what you have.

From what you posted you try to insert an account for a company with id '25300.38 ' which does not exist in your company table.

[Updated on: Thu, 02 January 2020 12:21]

Report message to a moderator

Previous Topic: WITH Clause VS INLINE View Execution
Next Topic: Raise exception in case clause PL/SQL function
Goto Forum:

Current Time: Wed Aug 17 23:57:49 CDT 2022