Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

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:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old November 6th, 2002, 11:14 PM
jmaker jmaker is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 13 jmaker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Oracle Trigger

I think I might need some help on creating a trigger. This is for my oracle class which isn't really that easy, that's why I'm asking for help here. I really want to get this working because it's extra credit and I know I'll need all the points I can get. Is there something wrong with this trigger so far? When I run an insert statement it should run the trigger right, and should come to the exception and print out that line and stop the insert but it doesn't, and I'm just not sure why.

create or replace trigger validate_library
before insert or update on Item for each row
DECLARE
e_book_not_found EXCEPTION;
e_dvd_not_found EXCEPTION;
e_bot_not_found EXCEPTION;
v_item_type Item.Item_Type%TYPE := :NEW.Item_Type;
v_checkout_period Item.Checkout_Period%TYPE := :NEW.Checkout_Period;
v_item_book_id Item.Item_Book_ID%TYPE := :NEW.Item_Book_ID;
v_item_dvd_id Item.Item_DVD_ID%TYPE := :NEW.Item_Dvd_ID;
v_item_tape_id Item.Item_Tape_ID%TYPE := :NEW.Item_Tape_ID;
BEGIN
IF v_item_type = 'Book' THEN
RAISE e_book_not_found;
END IF;

EXCEPTION
WHEN e_book_not_found THEN
DBMS_OUTPUT.PUT_LINE('item not in book');
WHEN e_dvd_not_found THEN
DBMS_OUTPUT.PUT_LINE('item not in dvd');
WHEN e_bot_not_found THEN
DBMS_OUTPUT.PUT_LINE('item not in book_on_tape');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('item not in any table');
END;


here's the insert statement:

insert into Item values(item_id_seq.NEXTVAL, 'Book', SYSDATE, '001', NULL, NULL);

and other useful code:

create sequence item_id_seq start with 1 nocache;

create table Item (
Item_ID number(12,0) not null primary key,
Item_Type varchar2(20) not null,
Checkout_Period date not null,
Item_Book_ID number(12, 0) null,
Item_Dvd_ID number(12, 0) null,
Item_Tape_ID number(12, 0) null );


obviously, this isn't the entire program. I've only just started on it, and it's making me mad. Thanks if anyone can help. But if no one can, believe me I'll understand. I barely understand this myself.

Reply With Quote
  #2  
Old November 7th, 2002, 02:50 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 5 h 22 m 58 sec
Reputation Power: 259
Why before insert?

Reply With Quote
  #3  
Old November 7th, 2002, 08:39 AM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 692 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 21 h 49 m 55 sec
Reputation Power: 19
Why are you doing this:

IF v_item_type = 'Book' THEN
RAISE e_book_not_found;

instead of just:

IF :new.item_type = 'Book' THEN
RAISE e_book_not_found;

I don't think the v_item_type variable has a value.

Reply With Quote
  #4  
Old November 7th, 2002, 04:02 PM
jmaker jmaker is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 13 jmaker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
why before insert? because that's our assignment.


IF :new.item_type = 'Book' THEN
RAISE e_book_not_found;

I tried this as well, but is it not supposed to display this line:
item not in book
but it doesn't...it just says that 1 row created when I insert a row. I thought it's just supposed to display the error line before the insert takes place. arrghh!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Oracle 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 4 hosted by Hostway