Solved

using/invoking trigger

Posted on 2012-04-11
2
462 Views
Last Modified: 2012-04-30
hi guys

In ORacle SQL Developer i see few triggers under the Triggers folder.

The goal of our trigger is to create a a new primary key which is stored in prod_id


create or replace TRIGGER prodschema.prod_ins_id
BEFORE
   INSERT ON prodschema.product
    FOR EACH ROW WHEN (NEW.prod_id IS NULL)
 
        BEGIN
        
          SELECT seq_prod_id.NEXTVAL   -- seq_prod_id is a sequence
                 , 'PROD_CODE' || seq_prod_id.CURRVAL
                 
          INTO  :NEW.prod_id
            , :NEW.prod_code
              
          FROM DUAL;
END;


what i want to know is we have a insert store procedure which inserts rows into the product  table. when this insert procedure is invoked, is the above trigger automatically called ?

I would also like to know what precautions to take when writing and invoking a trigger.

thanks
0
Comment
Question by:royjayd
2 Comments
 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 200 total points
ID: 37832761
>>is the above trigger automatically called ?

If the procedure does an insert into that table, then yes the trigger will fire.

>>I would also like to know what precautions to take when writing and invoking a trigger.

There is a large debate on this topic if you search around:
http://www.dba-oracle.com/m_trigger.htm
0
 
LVL 27

Accepted Solution

by:
sujith80 earned 300 total points
ID: 37832813
The trigger will fire automatically as long as it is ENABLED and VALID

To check if it is ENABLED run the below

select trigger_name, status, ut.*
from all_triggers ut
where owner = 'PRODSCHEMA'
trigger_name = upper('prod_ins_id');

to check the status
select status, ao.*
from all_objects ao
where owner = 'PRODSCHEMA'
and object_name = 'PROD_INS_ID'

>> what precautions to take when writing and invoking a trigger
Few of them
- if there are multiple triggers you need to take care of the sequencing of triggers
- Try to avoid complicated logic
- Try to avoid cross referencing of objects in triggers, this often leads to deadlocks
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now