[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • Last Modified:

what is the use of triggers in oracle?

Dear Experts,

Please describe the purpose of the triggers in oracle, Please give me a simple example.
0
haneef_nb
Asked:
haneef_nb
  • 3
1 Solution
 
slightwv (䄆 Netminder) Commented:
Is this a homework/exam question?

There are several types of triggers.  The short version is they perform some action on some event in the database.

The most common is a table level trigger.  Either  before or after event on DML.

I suggest you check he online docs.  They talk about all the different types and have several examples.
0
 
slightwv (䄆 Netminder) Commented:
Simple example (untested, typed in):

Create table tab1(col1 char(1));

Create or replace trigger tab1_trig
Before insert on tab1
For each row
Is
Begin
:new.col1 := upper(:new.col1);
End;
/

Show errors

Insert into tab1 values ('a');
Select * from tab1;
0
 
OP_ZaharinCommented:
- trigger commonly associated with table and view, used for triggering an action before or after an event takes place such as INSERT, UPDATE or DELETE.

- here is a sample of a trigger that i use to insert a running number (using sequence called tempseq) into a column call mykey whenever a new record is inserted into o_table1


CREATE OR REPLACE TRIGGER Temp_seq BEFORE INSERT ON o_Table1
FOR EACH ROW
BEGIN
SELECT tempseq.NEXTVAL into :new.mykey FROM dual;
END;


look more on trigger here: http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_triggers.htm
0
 
slightwv (䄆 Netminder) Commented:
Good doc excerpt but that doesn't talk about system triggers.
0
 
haneef_nbAuthor Commented:
thanks..
0

Featured Post

Technology Partners: 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!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now