I need to check a table for a record. If the record exists(WHERE clause will include the primary key column), I need to update it and if the record is not there, the entire fresh record need to be inserted. Can some one help me with the query?
And also what if the select query contains a WHERE on non key column?
I did something similar to this a couple of years ago. The requirement was that when a record was inserted into a table if it was a duplicate record (based on the PK) then the record would be updated instead of insert.
What we had to do was create a view of the base table and create an INSTEAD OF trigger on the view. Inside the INSTEAD OF trigger I performed an insert into the base table. If the insert failed because of a DUP_VAL_ON_INDEX exeption, I updated the base table via the PK with the new values. Then, I inserted data into the view.