Monday 26 June 2017

ORA-01446 when trying to delete in an Oracle Form that is based on a view with an instead of trigger

Issue.

The view that is used as the basis of a block contains a union or some other attribute that means the following error (ORA-01446: cannot select ROWID from, or sample, a view with DISTINCT, GROUP BY, etc) is raised when a record is deleted in the Form.


Solution.

By default Oracle Forms uses the rowid to work out the records to be updated and deleted. As we can't use the rowid in this case we need to change the block Key Mode from the default value of Automatic to Updateable


Then in the block set the items for the which ones define the primary key of the rows to be deleted or updated. These will be used in place of the rowid to do deletes or updates.Set the columns that are Key columns for each item.



Here are the details of the block Key Mode attribute from Oracle Forms help.
Updateable 
Specifies that Oracle Forms should issue UPDATE statements that include primary key values. Use this setting if your database allows primary key columns to be updated and you intend for the application to update primary key values.