Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
FaxWave - Free Trial.
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old November 3rd, 2003, 12:43 PM
vinhng9 vinhng9 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 4 vinhng9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Trigger insert, update, and delete

Hi,

Can someone please help me. I am a newbie in Pl/sql.

I like to write a trigger to insert, update, and delete a row.
When row is inserted/updated/deleted in table1, the same action is also applied for table2.

Thanks

Reply With Quote
  #2  
Old November 3rd, 2003, 01:34 PM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
According to Oracle dicumentation "A trigger associates with A table".
Say with me again "A trigger associates with A table"

Regards,

Reply With Quote
  #3  
Old November 6th, 2003, 06:58 PM
vinhng9 vinhng9 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 4 vinhng9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Trigger to insert/update/delete

shafique,

Yes, a trigger associates with table.

Here is the suituation:

If I insert data into table1, same data will be inserted into table2.
If I update data in table1, row with same primary key in table2 is also updated. Same for deleting.

Thanks

Reply With Quote
  #4  
Old November 7th, 2003, 03:06 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,401 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 6 h 24 m 39 sec
Reputation Power: 255
Why a view is not enough?

Reply With Quote
  #5  
Old November 7th, 2003, 09:19 AM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
Here is an example of world popular table 'EMP', I make another table 'EMP_TEMP' identical to EMP and now i want to update, insert and delete record from EMP_TEMP whenever an update, insert, and delete occured in emp. For this purpse i am creating a trigger called 'Emp_Ins_Upd_Del_Trig', complete list as follows.
CREATE or REPLACE TRIGGER Emp_Ins_Upd_Del_Trig
BEFORE delete or insert or update on EMP
FOR EACH ROW
BEGIN
if UPDATING then
UPDATE emp_temp
SET ename = :new.ename
, job = :new.job
, mgr = :new.mgr
, hiredate = :new.hiredate
, sal = :new.sal
, comm = :new.comm
, deptno = :new.deptno;
end if;

if INSERTING then
INSERT INTO emp_temp
VALUES( :new.empno
, :new.ename
, :new.job
, :new.mgr
, :new.hiredate
, :new.sal
, :new.comm
, :new.deptno);
end if;
if DELETING then
DELETE FROM emp_temp
WHERE empno = ld.empno;
end if;
END;
/

You first must test it by inserting, deleting and updating rows on emp table, Once you satisfied then apply it in your program.

Another option that you have is CREATE MATERIALIZED VIEW for any base table. It is a different from normal view, in normal view oracle only saves the query of that view in dictionary so that whenever you run any select statement on the normal view oracle reads the query from data dictionary and extract the data from tables, views those are using in creation of view's query, But it is rverse in the Materialized view, oracle stores the data instead of storing query.
Oracle implicitly keeps Materialized view identical to the base table.

Regards,

Reply With Quote
  #6  
Old November 7th, 2003, 10:03 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,401 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 6 h 24 m 39 sec
Reputation Power: 255
Personally I don't think that a materialized view has advantages over a traditional view unless there are aggregations or complex calculations or many joins in the object's definition, so my advice is to use a traditional view if you just need a subset of a table or to join two/three tables.

Reply With Quote
  #7  
Old November 24th, 2003, 04:33 PM
vinhng9 vinhng9 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 4 vinhng9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank you all.

Especially, thank to shafique. I got it now. It works as what I expected.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Trigger insert, update, and delete


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway