I am trying to raise an exception when the procedure does not insert a record. My code is as follows:
CREATE OR REPLACE PROCEDURE OPEN_CLASS(
p_class IN TUTPRAC.CLASSID%TYPE,
p_unitc IN TUTPRAC.UNITCODE%TYPE,
p_classd IN TUTPRAC.CLASS_DAY%TYPE,
p_classt IN TUTPRAC.CLASS_TIME%TYPE,
p_classtp IN TUTPRAC.CLASS_TYPE%TYPE,
p_roomnm IN TUTPRAC.ROOMNUM%TYPE)
IS
-- Variables
x number:=0;
y number:=0;
CLASS_CLASH EXCEPTION;
BEGIN
-- checks
SELECT nvl((SELECT 1
FROM TUTPRAC
WHERE UNITCODE = p_unitc and CLASS_DAY = p_classd
or CLASS_DAY = p_classd and CLASS_TIME = p_classt
and ROOMNUM = p_roomnm) , 0)
INTO x FROM dual;
SELECT nvl((SELECT 1
FROM UNITSTREAM
WHERE UNITCODE = p_unitc and DAY = p_classd
or DAY = p_classd and TIME = p_classt
and LOCATION = p_roomnm) , 0)
INTO y FROM dual;
-- insert
IF (x = 0 and y = 0) THEN
INSERT INTO TUTPRAC (CLASSID, UNITCODE, CLASS_DAY, CLASS_TIME, CLASS_TYPE, ROOMNUM)
VALUES (p_class, p_unitc, p_classd, p_classt, p_classtp, p_roomnm);
ELSE
RAISE CLASS_CLASH;
END IF;
EXCEPTION
WHEN CLASS_CLASH THEN
DBMS_OUTPUT.PUT_LINE('Record was not inserted due to a class clash.');
END OPEN_CLASS;
When I run this procedure, if the record does not have any clashes it says PL/SQL procedure successfully completed.
and it adds a record into the table. The problem is that even if it finds a clash and doesn't add a record it still says that same message instead of the output from my exception.