2014-04-01 29 views
-1

嗨,我是下的Oracle PL/SQL中一個初學者i'tried寫這個PL/SQL PROGRAMM但我有此錯誤:期待以下某種情況時遇到符號「WHILE」:。 (* @% - + /在環模餘REM

Encountered the symbol "WHILE" when expecting one of the following: . (* @ % & - +/at loop mod remainder rem ..'

SET SERVEROUTPUT ON 

DECLARE 

CURSOR EMP_CURSOR IS SELECT EMPLOYEE_NAME, SALARY, DATE_HIRE FROM EMPLOYEES WHERE DEPARTMENT_ID=1; 

BEGIN 

FOR EMP_REC IN EMP_CURSOR 
WHILE EMP_REC%FOUND 

    LOOP 
     IF EMP_REC.SALARY > 10000 AND EMP_REC.DATE_HIRE< DATE '2000-01-01' 
     THEN 
     DBMS_OUTPUT.PUT_LINE (EMP_REC.EMPLOYEE_NAME || ' earns ' || EMP_REC.SALARY || 'and joined the organization    on ' || EMP_REC.DATE_HIRE); 
     END IF; 
    END LOOP; 
END LOOP; 
END; 
/
SET SERVEROUTPUT OFF 

回答

0

試試這個:

DECLARE 

    CURSOR EMP_CURSOR IS SELECT EMPLOYEE_NAME, SALARY, DATE_HIRE FROM EMPLOYEES WHERE DEPARTMENT_ID=1; 

BEGIN 

FOR EMP_REC IN EMP_CURSOR 

    LOOP 
     IF EMP_REC.SALARY > 10000 AND EMP_REC.DATE_HIRE< DATE '2000-01-01' 
     THEN 
     DBMS_OUTPUT.PUT_LINE (EMP_REC.EMPLOYEE_NAME || ' earns ' || EMP_REC.SALARY || 'and joined the organization    on ' || EMP_REC.DATE_HIRE); 
     END IF; 
    END LOOP; 

END; 
+0

感謝您的答覆,我想這鱈魚它的工作的,但我不明白,爲什麼線,而EMP_REC%,實測值不與工作for循環和作品前時我使用了一個FETCH與光標?? – user2425416

+0

光標for循環做了一個隱式的open,fetch和close。沒有用在這裏使用EMP_REC%找到。這將是語法正確的,但會導致一個無限循環,你不在內聲明獲取:'BEGIN FOR EMP_REC IN EMP_CURSOR LOOP WHILE EMP_REC%FOUND LOOP - 做一些事情永遠 NULL; END LOOP; END LOOP;我不知道如何在評論中對此格式進行格式化...) – Nick

+0

嗨,我留下這個錯誤:PLS-00324:遊標屬性可能不適用於非遊標'EMP_REC 'for循環 – user2425416

相關問題