我有一个员工、司机和技工桌。司机不能是机械师,反之亦然,我需要创建一个过程 VERIFY 来验证此声明。目前我有这个。
CREATE OR REPLACE PROCEDURE VERIFY IS
ENAME VARCHAR(25);
MESSAGE VARCHAR(50) := 'OK';
CHECK1 BOOLEAN := FALSE;
DRIVERNUM TRKEMPLOYEE.E#%TYPE;
MECHANICNUM TRKEMPLOYEE.E#%TYPE;
CURSOR DRIVERNUM_CURSOR IS SELECT E# FROM TRKDRIVER;
CURSOR MECHANICNUM_CURSOR IS SELECT E# FROM TRKMECHANIC;
BEGIN
OPEN DRIVERNUM_CURSOR;
LOOP
FETCH DRIVERNUM_CURSOR INTO DRIVERNUM;
OPEN MECHANICNUM_CURSOR;
LOOP
FETCH MECHANICNUM_CURSOR INTO MECHANICNUM;
IF MECHANICNUM_CURSOR%NOTFOUND THEN
EXIT;
END IF;
IF (DRIVERNUM = MECHANICNUM) THEN
SELECT NAME INTO ENAME FROM TRKEMPLOYEE WHERE E# = DRIVERNUM;
DBMS_OUTPUT.PUT_LINE('EMPLOYEE#: ' || TO_CHAR(DRIVERNUM));
DBMS_OUTPUT.PUT_LINE('EMPLOYEENAME: ' || ENAME);
CHECK1 := TRUE;
END IF;
END LOOP;
CLOSE MECHANICNUM_CURSOR;
IF DRIVERNUM_CURSOR%NOTFOUND THEN
EXIT;
END IF;
END LOOP;
CLOSE DRIVERNUM_CURSOR;
IF CHECK1 = FALSE THEN
DBMS_OUTPUT.PUT_LINE(MESSAGE);
END IF;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('NULL');
END;
/
EXECUTE VERIFY;
它警告我说程序创建时有编译错误。请帮忙谢谢!而且在我的代码中也有说明,如果没有也注册为机械师的驱动程序,我需要它向我显示一条消息“OK”。