0

我有一个员工、司机和技工桌。司机不能是机械师,反之亦然,我需要创建一个过程 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”。

4

1 回答 1

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#

结果与您的许多循环、测试和查询产生的结果相同。

于 2013-11-15T10:38:07.850 回答