Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Filter Data on Before Delete Trigger...
arijitchatterjee123_at_yahoo.co.in wrote:
> Thanks Cris,Thanks for your response I was trying like this
> ...
> CREATE OR REPLACE TRIGGER CATEGORY_TRANS_DATA_DELETE
> BEFORE DELETE ON CATEGORY_TRANS
> FOR EACH ROW
> BEGIN
> DECLARE
> TOTAL_COUNT NUMBER(10,0);
> RESPONSE CHAR(2);
> BEGIN
> SELECT COUNT(*) INTO TOTAL_COUNT FROM CATEGORY_TRANS WHERE
> BLOG_ID=:OLD.BLOG_ID;
> IF TOTAL_COUNT = 1 THEN
> DBMS_OUTPUT.PUT_LINE('SINGLE RECORD FOUND...DO YOU WANT TO
> DELETE???? ...Y/N');
> END IF;
> END;
> END;
> ..
> And I made it.
> Thanks once again
> Regards
> Arijit Chatterjee
I'm surprised this trigger works for you, as it doesn't for me:
SQL> CREATE TABLE CATEGORY_TRANS(
2 BLOG_ID number(10), 3 CATEGORY_ID number(10));
Table created.
SQL> SQL> SQL> CREATE OR REPLACE TRIGGER CATEGORY_TRANS_DATA_DELETE2 BEFORE DELETE ON CATEGORY_TRANS
6 TOTAL_COUNT NUMBER(10,0); 7 RESPONSE CHAR(2); 8 BEGIN 9 SELECT COUNT(*) INTO TOTAL_COUNT FROM CATEGORY_TRANS WHERE 10 BLOG_ID=:OLD.BLOG_ID; 11 IF TOTAL_COUNT = 1 THEN 12 DBMS_OUTPUT.PUT_LINE('SINGLE RECORD FOUND...DO YOU WANT TO 13 DELETE???? ...Y/N'); 14 END IF; 15 END;
Trigger created.
SQL>
SQL> begin
2 for x in 1..100 loop 3 for y in 1..4 loop 4 insert into category_trans values (x,y); 5 end loop; 6 end loop;
PL/SQL procedure successfully completed.
SQL> SQL> SQL> delete from category_trans where blog_id = 1; delete from category_trans where blog_id = 1 *
I hope you get your problem solved.
David Fitzjarrell Received on Wed Mar 02 2005 - 12:54:47 CST