我正在尝试创建一个 PL/SQL 过程。但它不能正常工作。请查看代码并就此提出建议。
CREATE OR REPLACE PROCEDURE TEST IS
DECLARE
EMPLOYEENUM EMPLOYEE.E#%type;
EMPLOYEENAME EMPLOYEE.NAME%type;
NUMRECORDS NUMBER(2);
BEGIN
SELECT EMP.E# INTO EMPLOYEENUM ,EMP.NAME INTO EMPLOYEENAME
FROM EMPLOYEE EMP
WHERE EXISTS
(SELECT * FROM MECHANIC, DRIVER
WHERE EMP.E# = DRIVER.E#
AND EMP.E# = MECHANIC.E#);
SELECT COUNT(*) INTO NUMRECORDS
FROM (
SELECT EMP.E#,EMP.NAME
FROM EMPLOYEE EMP
WHERE EXISTS
(SELECT * FROM MECHANIC, DRIVER
WHERE EMP.E# = DRIVER.E#
AND EMP.E# = MECHANIC.E#));
IF (NUMRECORDS > 0) THEN
DBMS_OUTPUT.PUT_LINE('ERROR: CANNOT MAKE MORE THEN 2 TRIPS PER DAY');
ROLLBACK;
ELSE
COMMIT;
END IF;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
ROLLBACK;
END VERIFY;
而且我确信我不需要再次运行代码来查看行数。我知道有一种东西叫做
SQL%ROWCOUNT
它返回行数。请告知如何使用它。