Solved

Trigger PLSQL on column change

Posted on 2014-02-05
4
373 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
Comment Utility
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-
Comment Utility
tried that, doesnt seem to work.
0
 

Author Comment

by:FutureDBA-
Comment Utility
but the logic of what im trying to do is that
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

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…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
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.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now