Skip to content
Advertisement

How to create the correct trigger instead of insert or update? ORACLE. Trigger. pl/sql

Help create a trigger for a non-updatable view.

The tables look like this.

The view itself looks like this

I tried to create a trigger like this. But for some reason it is not created.( Error at line 86: PL/SQL: SQL Statement ignored Error at line 94: PL/SQL: ORA-00917: missing comma)

it seems to me that I went the hard way. help fix this code.

Advertisement

Answer

You say that you’re getting an error creating the trigger. But if I try to replicate your problem, I can’t because the definition of the Software table is invalid. First, the foreign key references a table Manufacturer that doesn’t exist in your example. And second, the foreign key constraint definition has an extra comma at the end.

If I remove the foreign key constraint entirely

That allows the script to get as far as trying to create the trigger. At that point, you’ll get errors which include (but are not limited to) the ORA-00917 error you mentioned.

The PLS-00049: bad bind variable errors occur because there are no columns called expiration_date or total_cost in the definition of the view. Thus, there is no such thing as :new.expiration_date or :new.total_cost because DML against the view cannot specify values for those columns. I have no idea how you want to handle that– either omit the values, provide default values, read the values from somewhere else, add the columns to the view and provide them in the DML against the view, etc. The fact that expiration_date is defined as not null seemingly limits your options.

If you look at line 86 of your trigger, you’ll see this statement

which isn’t syntactically valid.

would be valid if :new.expiration_date and :new.total_cost were valid identifiers. But, as mentioned above, they’re not valid. And it isn’t obvious what you would want the values to be on insert.

Here is a liveSQL example that you can play with to make sure what you have is a reproducible test case.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement