2009-06-15 13 views
0

über Explicit Cursors Lernen und versuchen, meine frst eines .:Was ist los mit diesem Cursor

SET SERVEROUTPUT ON 
DECLARE 
v_ename EMP.FIRST_NAME%TYPE; 
v_salary EMP.SALARY%TYPE; 
CURSOR c_emp IS SELECT first_name, salary FROM emp; 
BEGIN 
    OPEN c_emp; 
    FETCH c_emp INTO v_ename, v_salary; 
    DBMS_OUTPUT.PUT_LINE('Employee Details ' || v_ename || ' ' || v_salary) 

    FETCH c_emp INTO v_ename, v_salary; 
    DBMS_OUTPUT.PUT_LINE('Employee Details ' || v_ename || ' ' || v_salary) 

    CLOSE c_emp; 
END; 

zu schaffen, aber es gebe ich:

FETCH c_emp INTO v_ename, v_salary; 
    * 
ERROR at line 10: 
ORA-06550: line 10, column 3: 
PLS-00103: Encountered the symbol "FETCH" when expecting one of the following: 
:= . (% ; 
The symbol ";" was substituted for "FETCH" to continue. 
ORA-06550: line 13, column 3: 
PLS-00103: Encountered the symbol "CLOSE" when expecting one of the following: 
:= . (% ; 

Irgendwelche Ideen?

+1

Hmmm. Sie können es als die richtige Antwort dann markieren, so dass eine andere Person weiß, was die Auflösung für das Problem ist :) – Kirtan

Antwort

5

Haben Sie das Semikolon (;) nach dieser Zeile vergessen?

Line #9: DBMS_OUTPUT.PUT_LINE('Employee Details ' || v_ename || ' ' || v_salary); 

Versuchen Sie es hinzuzufügen und sehen Sie, ob der Fehler weiterhin besteht.

EDIT: Ja, es scheint, das fehlende Semikolon ist das Problem. Ihre Abfrage wurde aktualisiert. Versuche dies.

SET SERVEROUTPUT ON 
DECLARE 
    v_ename EMP.FIRST_NAME%TYPE; 
    v_salary EMP.SALARY%TYPE; 
CURSOR c_emp IS SELECT first_name, salary FROM emp; 
BEGIN 
     OPEN c_emp; 
     FETCH c_emp INTO v_ename, v_salary; 
     DBMS_OUTPUT.PUT_LINE('Employee Details ' || v_ename || ' ' || v_salary); 
     FETCH c_emp INTO v_ename, v_salary; 
     DBMS_OUTPUT.PUT_LINE('Employee Details ' || v_ename || ' ' || v_salary); 
     CLOSE c_emp; 
END; 
+0

Und noch einmal, zwei Zeilen nach unten. – UncleO

+0

das war es. Vielen Dank. -1 für hirnloses Kopieren von Buggy-Code direkt aus dem Buch. – udit

0

Ich glaube, dass in Oracle Sie können nicht FETCH <cursor> innerhalb der CURSOR <cursor> IS Aussage - vielleicht könnten Sie Ihren Code formatiert mehr ordentlich und/oder bessere Text Erklärung geben (im Idealfall beide! -) uns göttlich zu helfen, was in [[deleted Kraftausdruck ]] du versuchst zu tun ?!

+0

Formatierung erfolgt. – Kirtan