0 Replies Latest reply on Mar 21, 2013 3:37 PM by VJ_999

    How to make cursor record/variable dynamic or substitute variable


      I have couple of cursor records define in my PL/SQL procedures, they are all same structure type.
      For example
      C_rec_1 c_currsor%ROWTYPE;
      C_rec_2 c_currsor%ROWTYPE;
      C_rec_3 c_currsor%ROWTYPE;
      C_rec_4 c_currsor%ROWTYPE;
      C_rec_5 c_currsor%ROWTYPE;
      C_comm_rec c_currsor%ROWTYPE;


      fetch .... into C_rec_1;
      fetch .... into C_rec_2;
      fetch .... into C_rec_3;
      fetch .... into C_rec_4;
      fetch .... into C_rec_5;

      IF c_rec1.dept = 100 then
      C_comm_rec := c_rec1;
      END IF;
      IF c_rec2.dept = 100 then
      C_comm_rec := c_rec2;
      END IF;
      IF c_rec3.dept = 100 then
      C_comm_rec := c_rec3;
      END IF;
      IF c_rec4.dept = 100 then
      C_comm_rec := c_rec4;
      END IF;
      IF c_rec5.dept = 100 then
      C_comm_rec := c_rec5;
      END IF;

      Here rather than coding 5 IF statement, Can I make c_rec_? dynamic?

      Something like but this does not work :)

      For i IN 1..5 loop
      If c_rec_&l = 100 then
      C_comm_rec := c_rec5;
      End if
      End loop;