커서 에러가 뜨는데 질문드립니다 ㅠㅠ 0 4 2,153

by seon [2021.04.27 22:10:34]


set serveroutput on
declare 
    v_dept department%rowtype;
    cursor c1
    is
    select * from department;
begin
    dbms_output.put_line('부서번호  부서명  지역명');
    dbms_output.put_line('-----------------------------');
    open c1;
    loop
        fetch c1 into v_dept.dno, v_dept.dname, v_dept.loc;
        exit when c1 %notfound;
        dbms_output.put_line(v_dept.dno||'   '||v_dept.dname||'  '||v_dept.loc);
        end loop;
        close c1;
        end;

 

명령의 2 행에서 시작하는 중 오류 발생 -
declare 
    v_dept department%rowtype;
    cursor c1
    is
    select * from department;
begin
    dbms_output.put_line('부서번호  부서명  지역명');
    dbms_output.put_line('-----------------------------');
    open c1;
    loop
        fetch c1 into v_dept.dno, v_dept.dname, v_dept.loc;
        exit when c1 %notfound;
        dbms_output.put_line(v_dept.dno||'   '||v_dept.dname||'  '||v_dept.loc);
        end loop;
        close c1;
        end;


오류 보고 -
ORA-06550: line 2, column 12:
PLS-00201: identifier 'DEPARTMENT' must be declared
ORA-06550: line 2, column 12:
PL/SQL: Item ignored
ORA-06550: line 5, column 19:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 5, column 5:
PL/SQL: SQL Statement ignored
ORA-06550: line 11, column 23:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 11, column 9:
PL/SQL: SQL Statement ignored
ORA-06550: line 13, column 30:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 13, column 9:
PL/SQL: Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:
 

구글링해도 해결이 되지않아서 질문드립니다 ㅠㅠ 

by pajama [2021.04.27 22:32:19]

이런 식으로 하시면 됩니다~

 

SET SERVEROUTPUT ON;
DECLARE
CURSOR deptcur IS SELECT deptno, dname, loc FROM dept;
    myvar           deptcur%ROWTYPE;
BEGIN
    DBMS_OUTPUT.PUT_LINE( '부서번호  부서명  지역명' );
    DBMS_OUTPUT.PUT_LINE( '-----------------------------' );
    OPEN deptcur;
    LOOP
        FETCH deptcur INTO myvar;
        EXIT WHEN deptcur%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE( myvar.deptno || '  '  || myvar.dname || '  '  || myvar.loc );
    END LOOP;
    CLOSE deptcur;
END;

 


by seon [2021.04.27 23:06:04]

보내주신 코드로 하니 바로 되네요! 감사드립니다

근데 어떤 것 때문에 위 코드는 에러가 나는건가요??


by pajama [2021.04.27 23:15:34]

그러고보니..이게 테이블명이랑 컬럼명이 안맞아서 나는 오류 같은데요?


by seon [2021.04.28 17:30:50]

감사드립니다! 말씀하신대로 테이블명이 잘못되었더라구요

댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입