Solved

using/invoking trigger

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

Question has a verified solution.

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

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

867 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

16 Experts available now in Live!

Get 1:1 Help Now