plsql cursor to read the table

- The cursor read data to the table emp numbered get all the information by department. 
DECLARE 
                                                             
  Cursor C (NO emp.deptno % type) IS  SELECT  *  from EMP WHERE DEPTNO = NO;    - 1. cursor definition 
 
  type emp_table_type IS  Table  of EMP % ROWTYPE index  by BINARY_INTEGER;   - 2. define Table 
  emp_table emp_table_type;                                              - 4. Table 
 
  ROW1 EMP % ROWTYPE;    - 3. defined ROWTYPE 
the begin 
  OpenC ( 30 );   - input department number 
  FETCH C Bulk the collect INTO emp_table; - Batch Import 
  for I in emp_table.first..emp_table.last   - for convenience first loop from the table to the last emp_table.first..emp_table .last 
  Loop 
    dbms_output.put_line ( 
      ' the Cursor number ' || i || 
      ' ------ employee numbers == ' || emp_table (i) .empno || 
      ' ------ employee name == ' || emp_table (I) .ename 
    ); 
  End Loop; 
  close c;
end;

 

Guess you like

Origin www.cnblogs.com/ZXF6/p/11234104.html