Solved

using/invoking trigger

Posted on 2012-04-11
2
464 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 77

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ORA-02288: invalid OPEN mode 2 129
Reference datasets inside PL/SQL cursor and dumping queried datasets 3 56
Oracle Date 6 41
Oracle Join issue. 3 48
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

738 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