From: Nicholas Mudie <nmudie@chello.com>
To: 'pgsql-admin@postgresql.org' <pgsql-admin@postgresql.org>
Subject: TRIGGER HELP in oracle
Date: Thu, 22 Feb 2001 17:42:20 +0100
Message-ID: <99B219124BBED3119EF4009027CC89EF047BFDB0@nts_exch2.exchange.chello.com> (raw)
I'm trying to write an Oracle trigger and I hear this is the place I should
be. :)
trigger requirements:
A trigger that calulates the current volume PLUS the incoming volume.
Basically, I want to update the volume column based on the duplicate
billingid value that comes into the table.
i.e
I have
Billingid tbytesweekly
1234 9000
so, when new billingid comes into the table and it's 1234 with volume 1099 I
want the table to update the new volume of that billingid..SHOULD NOW =
10099 ;)
I have written this but it doesn't work, is there an easier way to do it????
CREATE TRIGGER upd_vol
BEFORE INSERT ON xact
FOR EACH ROW
DECLARE
totvol NUMBER;
BEGIN
SELECT SUM(tbytesweekly)
INTO totvol
FROM xact
WHERE billingid = :new.billingid
BEGIN
INSERT INTO xact
values (:new.billingid, totvol);
EXCEPTION
WHEN DUP_VAL_ON_INDEX
THEN
UPDATE xact
SET tbytesweekly = totvol
WHERE billingid = new:billingid;
END;
COMMIT;
END;
/
THANKS..:)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: nmudie@chello.com
Subject: Re: TRIGGER HELP in oracle
In-Reply-To: <99B219124BBED3119EF4009027CC89EF047BFDB0@nts_exch2.exchange.chello.com>
References: <99B219124BBED3119EF4009027CC89EF047BFDB0@nts_exch2.exchange.chello.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox