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
Solved

Trigger PLSQL on column change

Posted on 2014-02-05
4
382 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-
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
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 set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

829 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