Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Quick trigger question

Re: Quick trigger question

From: Matthias Gresz <GreMa_at_t-online.de>
Date: 1998/09/04
Message-ID: <6sodv8$e5n$1@news02.btx.dtag.de>#1/1

Hi,

tried this?

CREATE OR REPLACE TRIGGER DeleteSession
AFTER INSERT ON ccsds_www_session
FOR EACH ROW BEGIN DELETE FROM ccsds_www_session
  WHERE www_session_id = :new.www_session_id   AND www_user_id = :new.www_user_id
  AND row_id <> new.row_id;
END;
/

other way might be creating a before trigger:

CREATE OR REPLACE TRIGGER DeleteSession
BEFORE INSERT ON ccsds_www_session
FOR EACH ROW
Declare count_rows number;
BEGIN

	SELECT
		NVL(count(www_session_id),0)
	INTO
		count_rows
	FROM 
		ccsds_www_session
  	WHERE 
		www_session_id = :new.www_session_id
  	AND 
		www_user_id = :new.www_user_id
  	AND 
		row_id <> new.row_id;
	If count_rows > 0 then
		-- either raise application error
		-- or throw an exception that will be catched
		-- so the new row won't be added
	end if;

END;
/

mike_andrew_at_usiva.com schrieb:
>
> Creating a trigger on a table to delete the new row once it has already been
> inserted.
>
> Quick logic would say just delete the row where the row = :new.row
>
> Of course I get the extremely enjoyable mutating table error when I try to
> insert a row. I really don't have much time to devote to working this out,
> but I'm sure this is a quick answer for most of you.
>
> Here is the code for the trigger that returns the MT error when a row is
> inserted.
>
> CREATE OR REPLACE TRIGGER DeleteSession
> AFTER INSERT ON ccsds_www_session
> FOR EACH ROW
>
> BEGIN
>
> DELETE FROM ccsds_www_session
> WHERE www_session_id = :new.www_session_id
> AND www_user_id = :new.www_user_id;
>
> END;
> /
>
> Thank you in advance for your help !
> Mike
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum

-- 

Regards

Matthias Gresz    :-)

--
Matthias.Gresz_at_Privat.Post.DE

          /|
         / |        
        /| |\
       /||  |\
      / O    |\         
     |        |\ Galopping Horse beats Running Man.
    /          |\
   /      /     |\
  /    __/|      |\
  \°   /  |       |\
   \/_/   |        |\
Received on Fri Sep 04 1998 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US