%ROWTYPE
In PL/SQL, records are used to group data. A record consists of a number of related fields in which data values can be stored. The %ROWTYPE attribute provides a record type that represents a row in a table. The record can store an entire row of data selected from the table or fetched from a cursor or cursor variable.Columns in a row and corresponding fields in a record have the same names and datatypes. In the example below, you declare a record named dept_rec. Its fields have the same names and datatypes as the columns in the dept table.DECLARE
   dept_rec dept%ROWTYPE;  -- declare record variable
You use dot notation to reference fields, as the following example shows:my_deptno := dept_rec.deptno;
If you declare a cursor that retrieves the last name, salary, hire date, and job title of an employee, you can use %ROWTYPE to declare a record that stores the same information, as follows:DECLARE
   CURSOR c1 IS
      SELECT ename, sal, hiredate, job FROM emp;
   emp_rec c1%ROWTYPE;  -- declare record variable that represents
                        -- a row fetched from the emp table
When you execute the statementFETCH c1 INTO emp_rec;

解决方案 »

  1.   

    erec emp%ROWTYPE;:定义了一个变量为表emp中行的类型
     SELECT * INTO erec 将一行数据存入变量erec中
      

  2.   

    erec emp%ROWTYPE;
          SELECT * INTO erec 
           FROM emp      
           WHERE empno=&雇员编号;第一行:定义一个变量,类型为表emp中的行,即包含各个字段的行类型,类似于结构
    第二行--第四行:表示在表中选取一条记录存入到变量erec 中
      

  3.   

    %ROWTYPE表示 定义的SQL变量erec是按照emp表结构定义的。此用法的好处是,随着EMP表的结构的变化,定义的变量erec也随着表结构自动变化。书上都有。