Solved

Trigger PLSQL on column change

Posted on 2014-02-05
4
384 Views
Last Modified: 2014-02-17
Hello Experts,

I have 2 tables, I want to create a trigger to execute a PLSQL block when the status on CREDIT_HEADER changes from null to 1

BEGIN
INSERT INTO CREDIT_MASTER (CID, CDATE, CHAIN, CUSTOMER, REP, ROUTE, CRAMT)
SELECT
  H.CID,
  H.CDATE, 
  H.CHAIN, 
  H.CUSTOMER,
  H.REP,
  NULL ROUTE,
  sum(QTY*ITMPRC) CRAMT
FROM CREDIT_HEADER H, CREDIT_DETAIL D
WHERE H.CID = D.CID
  AND H.STATUS is 1
GROUP BY 
  H.CID,
  H.CDATE, 
  H.CHAIN, 
  H.CUSTOMER,
  H.REP;
  commit;
  update CREDIT_HEADER set status = 2 where status = 1 and REP is not null;
  commit;
  END;

Open in new window

 
 
CREDIT_HEADER
-----------------------------
CID      NOT NULL VARCHAR2(9)   
CDATE             DATE          
CHAIN             VARCHAR2(6)   
CUSTOMER          VARCHAR2(6)   
CNAME             VARCHAR2(20)  
CCOMMENT          VARCHAR2(120) 
REP               VARCHAR2(15)  
STATUS            VARCHAR2(2)   

Open in new window


CREDIT_MASTER
----------------------------
desc credit_master
Name     Null     Type         
-------- -------- ------------ 
CID      NOT NULL VARCHAR2(9)  
CDATE             DATE         
CHAIN             VARCHAR2(6)  
CUSTOMER          VARCHAR2(6)  
REP               VARCHAR2(15) 
ROUTE             VARCHAR2(20) 
CRAMT             NUMBER       

Open in new window

0
Comment
Question by:FutureDBA-
[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
4 Comments
 
LVL 26

Accepted Solution

by:
arober11 earned 500 total points
ID: 39838480
Something like:

CREATE OR REPLACE TRIGGER CREDIT_HEADER_Status_update
  AFTER  INSERT OR UPDATE ON CREDIT_HEADER
  FOR EACH ROW
WHEN (new.STATUS is not null)
BEGIN
......
END

Open in new window

0
 

Author Comment

by:FutureDBA-
ID: 39841049
tried that, doesnt seem to work.
0
 

Author Comment

by:FutureDBA-
ID: 39841050
but the logic of what im trying to do is that
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39841712
Please define "doesn't work".  Does it cause your server to crash?  Your monitor to turn pink?

Can you also provide a simple test case with data and expected results?

It would also help if you could post the trigger code you tried.
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-00923: FROM keyword not found where expected 3 95
oracle collections 2 28
subtr returning incorrect value 8 65
oracle query 3 26
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
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.

756 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