1

I'm working on my project for simple forum. For storing the datas i've database schema as:

Database design

To view the questions posted by the users easier i've created a view as

create view users_questions as select qid,username,questions from userinfo natural
join posts natural join questions

I am trying to create a trigger on that view to insert the data actually inserted into the table questions and post. I have basic knowledge on creating the trigger for tables[Had knowledge of trigger to backup the table rows when deleted]. But confused in case of the views, weather the instead trigger can be used in case of views to insert the data's into other tables.

Edited With My Try For Creating The Trigger

CREATE OR REPLACE TRIGGER TRIGGER1 
INSTEAD OF INSERT ON USERS_QUESTIONS 
BEGIN
    insert into questions values(new.qid,new.questions);  
END;

Not working shows error like:

Error(4,5): PL/SQL: SQL Statement ignored Error(4,46): PL/SQL:
ORA-00984: column not allowed here

5
  • 1
    What is your question here? If such triggers are possible? Yes, the documentation suggests that. Commented Aug 3, 2018 at 20:00
  • How to get the values that a user is trying to insert? Commented Aug 3, 2018 at 20:15
  • 1
    Be warned, by using triggers, you are putting a rope around your neck. Oracle recommends NOT to implement business logic with triggers. Commented Aug 3, 2018 at 20:18
  • Sorry not concerned about the oracle issues, for understanding the trigger uses. But thanks for the kind info @Ychdziu. Will never use in real life projects. Commented Aug 3, 2018 at 20:21
  • 2
    Coding suggestions - don't use NATURAL JOIN, as it makes it very difficult to determine what the join conditions are. Always state the join conditions explicitly so that everyone can see them. And always include a field list on your INSERT statements - that way your INSERTs will either still work after the table is modified, or you'll be able to easily find the statements which need to be updated. Best of luck. Commented Aug 4, 2018 at 3:25

1 Answer 1

1

You need:

insert into questions values(:new.qid, :new.questions);

Colons in front of NEW

Sign up to request clarification or add additional context in comments.

1 Comment

Or else add USING NEW AS NEW, OLD AS OLD to the trigger definition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.