why am i not able to see the exception message?
438970Dec 3 2005 — edited Dec 6 2005i wrote an 'instead of insert' trigger on a view.
and there are some exception situations in which the insertion should be stopped. my trigger works correctly. i mean it implements its purpose. however, the message i am taking after the trigger execution is not satisfying. ( i am using iSQL*Plus as the editor.)
here is my trigger: (after trigger there is some extra explanation below.)
**********************
CREATE OR REPLACE TRIGGER DemandOfCourses_T1_II
INSTEAD OF INSERT ON DemandOfCourses
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
cpc NUMBER;
currentNum NUMBER;
stud1 NUMBER;
stud2 NUMBER;
prec NUMBER;
exc1 EXCEPTION;
exc2 EXCEPTION;
BEGIN
SELECT capacity
INTO cpc
FROM LimitedCourse
WHERE course = :NEW.course;
IF cpc IS NULL THEN
cpc := 1000;
END IF;
SELECT COUNT(course)
INTO currentNum
FROM Registered
WHERE course = :NEW.course;
SELECT COUNT(student)
INTO stud1
FROM Registered
WHERE student = :NEW.student
AND course = :NEW.course;
SELECT COUNT(student)
INTO stud2
FROM WaitingFor
WHERE student = :NEW.student
AND course = :NEW.course;
SELECT COUNT(hp.preCourse)
INTO prec
FROM HasPrereq hp
WHERE hp.course = :NEW.course
AND hp.preCourse NOT IN (SELECT course FROM CourseResult WHERE student = :NEW.student);
IF (prec = 0) THEN
IF (stud1 = 0) AND (stud2 = 0) THEN
IF (currentNum = cpc) THEN
INSERT INTO WaitingFor
VALUES (:NEW.student, :NEW.course, SYSDATE);
ELSE
INSERT INTO Registered
VALUES (:NEW.student, :NEW.course);
END IF;
ELSE
RAISE exc1;
END IF;
ELSE
RAISE exc2;
END IF;
EXCEPTION
WHEN exc1 THEN
RAISE_APPLICATION_ERROR (-20002, 'Already registered for this course.');
WHEN exc2 THEN
RAISE_APPLICATION_ERROR (-20003, 'First the prerequesite course(s) must be taken.');
WHEN NO_DATA_FOUND THEN
NULL;
END;
**********************
for eample, if i want to insert the row below:
----------------------------------
INSERT INTO DemandOfCourses VALUES (100005, 'BAK127', 'REGISTERED');
-- 100005 : STUDENT ID
-- BAK127 : COURSE CODE
-- REGISTERED : SITUATION
-----------------------------------------
when i run this insert comment, i receive this result:
----------------
1 row created.
----------------
Actually, it should not insert anything. and it is not inserting anything. i mean, it is working correctly. however, i want it to write my exception message: "-20003, 'First the prerequesite course(s) must be taken.'"
why cannot i see my expected exception message?
all the data and structure is certainly true. if you have a question about them, i can answer.
by the way, i will catch this exception from my java code. what should i do in this situation?
any help will be appreciated.
regards