Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > Oracle
|
Oracle General Oracle database discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Oracle section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 28th, 2005, 12:54 PM
Registered User
 
Join Date: Feb 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Oracle Trigger help please...

Hello - I've been working on a trigger that I want to use to update a field on a table(tisfc951) if that same field on another table(tdsls040) is changed. There isn't a direct link between these tables so I have to query two other tables to get the order number I need to get the correct record(s) updated in my final table(tisfc951). There can be more than one record in my final table to be updated. I'm thinking I need to use a cursor but I'm having difficulty because to populate the cursor I need two of the :new.fields and I'm seeing cursors need to be created outside of the BEGIN/END right? I've posted the non-cursor code I've been working with. I hope this explanation is understandable - any help would be great!!

NikkiZ



CREATE OR REPLACE TRIGGER "BAAN"."UPDATE_BC_JOBS" AFTER
UPDATE OF "T$EONO" ON "BAAN"."TTDSLS040795" FOR EACH ROW
DECLARE

    ws_eono VARCHAR2(30);
    ws_cprj VARCHAR2(6);
    ws_pdno NUMBER(6);
    ws_orno NUMBER(6);


BEGIN

    ws_eono := :new.t$eono;
    ws_orno := :new.t$orno;

    SELECT Lines.t$cprj, Pdnohead.t$pdno
    INTO ws_cprj, ws_pdno
    FROM ttdsls041795 Lines, ttisfc001795 Pdnohead
    WHERE Lines.t$orno = :new.t$orno
    AND Lines.t$cprj = Pdnohead.t$cprj;

LOOP
      UPDATE ttisfc951795
    SET t$eono = ws_eono
    WHERE t$pdno = ws_pdno;
END LOOP;

END;

 
Old March 2nd, 2005, 06:05 AM
Registered User
 
Join Date: Feb 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to SureshHyd
Default

I think you can declare parameterized cursor in declaration block and open it up in trigger block. Pass :new values as parameters to it and loop thru. i haven't checked the following code for syntax errors since oracle is not available with me now. Hope this would of help to you.

CREATE OR REPLACE TRIGGER "BAAN"."UPDATE_BC_JOBS" AFTER
UPDATE OF "T$EONO" ON "BAAN"."TTDSLS040795" FOR EACH ROW
DECLARE

    ws_eono VARCHAR2(30);
    ws_cprj VARCHAR2(6);
    ws_pdno NUMBER(6);
    ws_orno NUMBER(6);
    CURSOR C(Ordno lines.t$orno%type) IS SELECT Lines.t$cprj, Pdnohead.t$pdno
              FROM ttdsls041795 Lines, ttisfc001795 Pdnohead
              WHERE Lines.t$orno = ordno
              AND Lines.t$cprj = Pdnohead.t$cprj;

BEGIN
    ws_eono := :new.t$eono;
    OPEN C(:new.t$orno);
    LOOP
       EXIT WHEN SQL%NOTFOUND;
       FETCH C INTO ws_pdno;
       UPDATE ttisfc951795
       SET t$eono = ws_eono
       WHERE t$pdno = ws_pdno;
    END LOOP;
END;





Similar Threads
Thread Thread Starter Forum Replies Last Post
Oracle SOA, BPEL and Oracle worklist umeshtheone Pro Java 1 April 16th, 2008 11:01 PM
oracle database trigger jlnashrod Oracle 1 October 3rd, 2007 12:41 AM
call oracle function using oracle link server vl SQL Server 2000 1 July 12th, 2007 08:19 AM
oracle trigger (how to move forward) timbal25 Oracle 0 July 18th, 2006 10:27 AM
How to Read Oracle Data without Oracle being insta badrinarayanang Oracle 1 October 6th, 2005 06:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.