0

了解显式游标并尝试创建我的第一个。:

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;

但它给了我:

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:
:= . ( % ;

有任何想法吗 ?

4

2 回答 2

5

您是否忘记了这行后面的分号 (;)?

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

尝试添加它,看看错误是否仍然存在。

编辑:是的,似乎缺少分号是问题所在。更新了您的查询。试试这个。

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;
于 2009-06-15T05:25:10.513 回答
0

我相信在 Oracle 中,你不能FETCH <cursor>CURSOR <cursor> IS语句内部——也许你可以更整齐地格式化你的代码和/或提供更好的文本解释(最好是两者!-)来帮助我们判断你在 [[expletive deleted]] 中尝试的内容去做?!

于 2009-06-15T05:19:12.090 回答