Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old July 7th, 2004, 02:58 AM
witi witi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 5 witi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Before Delete Trigger

Hi!

I have a realy annoying problem...
here is the code...
Code:
CREATE OR REPLACE TRIGGER RechtMgrDel
BEFORE DELETE ON benrecht
FOR EACH ROW
BEGIN
  if :old.gname<>'--' then
	RAISE_APPLICATION_ERROR(-20901,'dont do it!');
  end if;
END;
/
SHOW ERROR;


if the trigger finds a row, it is not allowed to delete, the message is displayed and the triggeractions are rolledback...
I want the triger to delete the rows, which are allowed to delete
and to leave the rows, which are not allowed to delete..
HOW????

Reply With Quote
  #2  
Old July 7th, 2004, 03:08 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,711 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 6 Days 4 h 53 m 59 sec
Reputation Power: 259
Use an INSTEAD OF trigger that does something instead of deleting. See http://www.psoug.org/reference/instead_of_trigger.html

Reply With Quote
  #3  
Old July 7th, 2004, 03:17 AM
witi witi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 5 witi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
hm

hi!

i thought, INSTEAD OF trigger are only allowed on views??

Reply With Quote
  #4  
Old July 7th, 2004, 03:51 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,766 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 6 h 24 m 8 sec
Reputation Power: 37
Yes. So

Code:
create view mc as select * from benrecht


Code:
CREATE OR REPLACE TRIGGER RechtMgrDel
instead of DELETE ON mc
FOR EACH ROW
BEGIN
  if :old.gname<>'--' then
	delete from benrecht
     where pk = :old.pk;
  end if;
END;
/

SHOW ERROR;

Reply With Quote
  #5  
Old July 7th, 2004, 03:57 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,711 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 6 Days 4 h 53 m 59 sec
Reputation Power: 259
sorry, I was in MsSQL mode .... you are right, my fault

Reply With Quote
  #6  
Old July 7th, 2004, 04:09 AM
witi witi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 5 witi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thank you!
I also had this solution... but im new to oracle
and though there might be some magic word..
SKIP ROW
or something like that

Reply With Quote
  #7  
Old July 7th, 2004, 08:01 AM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
I would like to do it as follows.
Please be noted that it is only pseudo code not the complete implementation, you can write the code if you think it is worth for you.

CREATE OR REPLACE TRIGGER RechtMgrDel
BEFORE DELETE ON benrecht
FOR EACH ROW
BEGIN

Check_Validity_Of_Data (parameter list);

END;
/
SHOW ERROR;


CREATE OR REPLACE PROCEDURE Check_Validity_Of_Data (pamater list) IS
.....
.....
.....
BEGIN
.....
.....
.....

IF param1 = this_value THEN
RAISE_APPLICATION_ERROR('This record could not be deleted.....');
END IF;

END Check_Validity_Of_Data;
/

Regards,

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Before Delete Trigger


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway