Solved

Trigger PLSQL on column change

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

Industry Leaders: 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

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…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

695 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