Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generating an error using a trigger

Status
Not open for further replies.

wizardofsilence

IS-IT--Management
Jul 29, 2012
12
LK
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


 
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;

 
@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-


thanks for the help..
 
Yes, that's exactly what I would expect to appear.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top