Solved

Trigger PLSQL on column change

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

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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 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…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

816 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

10 Experts available now in Live!

Get 1:1 Help Now