cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Unique Constraint Issue in Oracle while inserting Data

sshaik
New Contributor III

In this Scenario, I have to insert data onto an Oracle DB. Before that one Iโ€™m performing a Left Outer join and separating the data (for Update and Insert) by using router. In Insert snap I have to insert all the data ,before that one Need to check whether the data is matching with Target table / not . If yes ignore those records if not then perform insert . This was the whole logic .
I have to take data columns from mapper and check the columns with oracle target table if data is already exists/not. But, Unfortunately It was troughing errors.

INSERT INTO Schema.tablename (DEST,FROM_D,INSRT_BY,INSRT_DT,LVL,TO_D,UPDT_DT) VALUES (โ€˜โ€œ+$DEST+โ€โ€™,โ€˜โ€œ+$FROM_D+โ€โ€™,โ€˜โ€œ+$INSRT_BY+โ€โ€™,โ€˜โ€œ+$INSRT_DT+โ€โ€™,โ€˜โ€œ+$LVL+โ€โ€™,โ€˜โ€œ+$TO_D+โ€โ€™,โ€˜โ€œ+$UPDT_DT+โ€โ€™) WHERE (DEST<>โ€˜โ€œ+$DEST +โ€โ€™ AND LVL<>โ€˜โ€œ+$LVL +โ€โ€™)

Where condition columns are Primary Keys to the table.
DEST,FROM_D,INSRT_BY,INSRT_DT,LVL,TO_D,UPDT_DT ---- Table columns
โ€˜โ€œ+$DEST+โ€โ€™,โ€˜โ€œ+$FROM_D+โ€โ€™,โ€˜โ€œ+$INSRT_BY+โ€โ€™,โ€˜โ€œ+$INSRT_DT+โ€โ€™,โ€˜โ€œ+$LVL+โ€โ€™,โ€˜โ€œ+$TO_D+โ€โ€™,โ€˜โ€œ+$UPDT_DT+โ€โ€™ ---- Mapper columns/Data

I think Experts will find a best solution for this issue.
@bojanvelevski @del @AleksandarAngelevski @Spiro_Taleski

Please help on this issue.
image

1 ACCEPTED SOLUTION

sshaik
New Contributor III

Solved this scenario in a different way.
Insert handled by using inner join.
For Update
Here I have to update 2 columns($status, $ID) based on 6 key columns matching data.
So, I have read the target table as reference table($col_Ref) and regular/new data as left side data and performing an inner join based on 6 key columns.
There I found the matching data.
I put 1 filter to sort $status=โ€œActiveโ€
I just mapped 2 ($status hardcoded as โ€œINACTIVEโ€ I have to update the $status column if $stat=โ€œActiveโ€, $ID taken from filter ) columns which I want to update in the Target Table.

Finally in Oracle Update snap mentioned Schema and table name.
In where clause $Status=โ€œActiveโ€.
image

This was one of the ways that I found for resolving this issue.

If we have any other ways to handle this, then it could be helpful.

View solution in original post

3 REPLIES 3

del
Contributor III

@sshaik, I donโ€™t have an Oracle DB with which I can test this suggestion, so consider it with that disclaimer; but I think what you may need to do is modify your WHERE query to be a NOT EXISTS subquery.

Something similar too:

WHERE NOT EXISTS (SELECT NULL FROM Schema.tablename WHERE DEST = $DEST AND LVL = $LVL)

sshaik
New Contributor III

Thanks for the reply.
The WHERE condition why I wrote like that means I canโ€™t read the data from any table . Itโ€™s a combination of 2 tables data then have to perform Change capture (update,delete,insert). So, is there any option to resolve this issue?

Not able to read/fetch those mapper columns in the DB snap thatโ€™s the issue here.

What I want is how to write the query without selecting data from DB , by using WHERE clause we have to do .

sshaik
New Contributor III

Solved this scenario in a different way.
Insert handled by using inner join.
For Update
Here I have to update 2 columns($status, $ID) based on 6 key columns matching data.
So, I have read the target table as reference table($col_Ref) and regular/new data as left side data and performing an inner join based on 6 key columns.
There I found the matching data.
I put 1 filter to sort $status=โ€œActiveโ€
I just mapped 2 ($status hardcoded as โ€œINACTIVEโ€ I have to update the $status column if $stat=โ€œActiveโ€, $ID taken from filter ) columns which I want to update in the Target Table.

Finally in Oracle Update snap mentioned Schema and table name.
In where clause $Status=โ€œActiveโ€.
image

This was one of the ways that I found for resolving this issue.

If we have any other ways to handle this, then it could be helpful.