我有一个员工,司机和机械表。驱动程序不能是机制,反之亦然,我需要创建一个过程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”。
答案 0 :(得分:0)
您的代码过于复杂。要找出那些同时是机制和驱动程序的人,请循环查询:
SELECT d.E#, e.NAME
FROM TRKDRIVER d
JOIN TRKMECHANUC m on m.E# = d.E#
JOIN TRKEMOYEE e on e.E# = d.E#
结果与许多循环,测试和查询产生的结果相同。