INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Generating an error using a trigger

Generating an error using a trigger

(OP)
I need to make a trigger which generates an error when value 'AUGUST' is entered as evdata in event.
Q- ensure that event cannot be run in the month of AUGUST.

I created the following trigger but the rows can be entered which include 'AUGUST' as data.


create or replace trigger trigtest
BEFORE INSERT OR UPDATE OF evdate ON event
FOR EACH ROW

BEGIN

IF TO_CHAR(:NEW.evdate,'MONTH') = 'AUGUST' THEN
RAISE_APPLICATION_ERROR(-20101,'OUT OF RANGE');
END IF;

END;


INSERT INTO Event VALUES(005,'11-AUG-2012','18:00',21,9003); -- this value can be entered.

Thanks alt
GKD


RE: Generating an error using a trigger

"Month" appears to pad the month name with spaces (presumably to the length of the longest month). Trimming it should fix the problem:

CODE

create or replace trigger trigtest
BEFORE INSERT OR UPDATE OF evdate ON event
FOR EACH ROW
BEGIN
  IF TRIM(TO_CHAR(:NEW.evdate,'MONTH')) = 'AUGUST' THEN
  RAISE_APPLICATION_ERROR(-20101,'OUT OF RANGE');
  END IF;
END; 

RE: Generating an error using a trigger

(OP)
@Dagon

yeahh... I think it is solved...But are those messages suppose to appear

INSERT INTO Event VALUES(005,'11-AUG-2012','18:00',21,9003);

gives the msg-

Quote (ORA-20101: OUT OF RANGE
ORA-06512: at "TEST.TRIGTEST", line 3
ORA-04088: error during execution of trigger 'TEST.TRIGTEST'

1. INSERT INTO Event VALUES(006,'11-AUG-2012','15:00',21,9003);)


thanks for the help..

RE: Generating an error using a trigger

Yes, that's exactly what I would expect to appear.

RE: Generating an error using a trigger

(OP)
@Dagon

Thanks alt... thumbsup2

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close