title: Can not solve the reference cursor errors in PL/SQL
body: <p>PL/SQL reference cursor:</p>
  <pre><code>DECLARE
    TYPE cur IS REF CURSOR;
    c1   cur;
    emp  emp_table%ROWTYPE;
    stmt VARCHAR2(200) := 'select * from emp_table';
    CURSOR c2 IS
      SELECT DISTINCT dept_id FROM emp_table;
  BEGIN
    FOR i IN c2 LOOP
      dbms_output.put_line('the department no is ' || i.dept_id);
    END LOOP;
  
    IF i.dept_id IS NULL THEN
      OPEN c1 FOR stmt;
    ELSE
      stmt := stmt || ' where dept_id = i.dept_id';
      OPEN c1 FOR stmt USING i.dept_id;
    END IF;
  
    LOOP
      FETCH c1 INTO emp;
      EXIT WHEN c1%NOTFOUND;
      dbms_output.put_line(c1.dept_id || ' , ' || c1.emp_name || ' , ' || c1.emp_sal);
    END LOOP;
  
    CLOSE c1;
  
  END;
  /
  </code></pre>
  <p>errors I got are</p>
  <pre><code>**ORA-06550: line 11, column 4:                           
  PLS-00201: identifier 'I.DEPT_ID' must be declared                 
  ORA-06550: line 11, column 1:                 
  PL/SQL: Statement ignored                      
  ORA-06550: line 19, column 25:                     
  PLS-00487: Invalid reference to variable 'C1'                   
  ORA-06550: line 19, column 1:                          
  PL/SQL: Statement ignored                       
  06550. 00000 -  &quot;line %s, column %s:\n%s&quot;                    
  *Cause:    Usually a PL/SQL compilation error.                           
  *Action:**                  
  </code></pre>
  <p>I tried running the above code and getting errors.
  Please help me to solve this error. Please tell me the good links to study PL/SQL.</p>