日期:2014-05-17  浏览次数:20659 次

這哪錯了?請幫更正,謝謝!
SQL code

[code=SQL]
declare 
type eName is recrod(
        emp_name emp.ename%type
);
empName eName;
cursor c1 is select ename from emp;
begin
    open c1;
    loop
        fetch c1 into empName;
        exit when c1%notfound;
        dbms_output.put_line(empName.emp_name);
    end loop;
    close c1;
end;
/


[/code]

------解决方案--------------------
才看到 你的record 写错了~ 你写成recrod了
SQL code

declare
  type eName_record is record(emp_name emp.ename%type);
  empName eName_record;
  cursor c1 is
    select ename from emp;
begin
  open c1;
  loop
    fetch c1
      into empName.emp_name;
    exit when c1%notfound;
    dbms_output.put_line(empName.emp_name);
  end loop;
  close c1;
end;

------解决方案--------------------
知道了,你的语句哪里复制黏贴的?带有特殊字符


用我下面的这个

SQL code
SQL> DECLARE
  2    TYPE ENAME IS RECORD(
  3      EMP_NAME emp.ename%TYPE);
  4    EMPNAME ENAME;
  5    CURSOR C1 IS
  6      SELECT ENAME FROM EMP;
  7  BEGIN
  8    OPEN C1;
  9    LOOP
 10      FETCH C1
 11        INTO EMPNAME;
 12      EXIT WHEN C1%NOTFOUND;
 13      DBMS_OUTPUT.PUT_LINE(EMPNAME.EMP_NAME);
 14    END LOOP;
 15    CLOSE C1;
 16  END;
 17  
 18  /
 
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
 
PL/SQL procedure successfully completed