while executing below code it showing error

user2775287 picture user2775287 · Sep 16, 2013 · Viewed 10.2k times · Source

This is my pl/sql program:

 declare
   m_no      emp.emp_no%rowtype;
   m_name    emp.emp_name%rowtype;
   m_address emp.address%rowtype;
   cursor raju is 
     SELECT emp_no,
            emp_name,
            address 
       from emp;
 begin
   open raju;
   loop
     fetch raju 
      into m_no,
           m_name,
           m_address;
     dbms_output.put_line(m_no ||''||m_name||''||m_address);
     EXIT WHEN raju%notfound;
   end loop;
   close raju;
 end;

while executing above code am getting error

Error report:
ORA-06550: line 2, column 6:
PLS-00310: with %ROWTYPE attribute, 'EMP.EMP_NO' must name a table, cursor or cursor-variable
ORA-06550: line 2, column 6:
PL/SQL: Item ignored
ORA-06550: line 3, column 8:
PLS-00310: with %ROWTYPE attribute, 'EMP.EMP_NAME' must name a table, cursor or cursor-variable
ORA-06550: line 3, column 8:
PL/SQL: Item ignored
ORA-06550: line 4, column 11:
PLS-00310: with %ROWTYPE attribute, 'EMP.ADDRESS' must name a table, cursor or cursor-variable
ORA-06550: line 4, column 11:
PL/SQL: Item ignored
ORA-06550: line 10, column 18:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 10, column 2:
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 2:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:

but I didn't get where it showing and where it error occurring. Any one suggest me please.

Answer

Noel picture Noel · Sep 16, 2013

Your variable declaration is wrong.

Since you are selecting and storing the columns separately, you should declare it using %TYPE attribute.

m_no      emp.emp_no%type;
m_name    emp.emp_name%type;
m_address emp.address%type

%ROWTYPE attribute is used if you are using single variable to store all columns.

m_emp emp%rowtype