Solved

using/invoking trigger

Posted on 2012-04-11
2
460 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

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…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

760 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

22 Experts available now in Live!

Get 1:1 Help Now