title: how to create dynamic variable name inside a for loop in sql
body: <p>I am new to sql. not an expert. I have a proc where i need to extract some values from two tables using a key
  tables ord_item and product_ext_data view_id is the key.</p>
  
  <p>i want to extract the param_value from the product_ext_data into variables d_DestNumber1,d_DestNumber2 ...d_DestNumber10(max 10 values expected)</p>
  
  <p>For this i am using the for loop to iterate through the cursor output and assign each param_value to  each variable.
  I am not sure how to create the variable name dynamically based on the i value in the for loop</p>
  
  <pre><code>               CREATE OR REPLACE PROCEDURE C1_REMOVEFNFDATA(v_soid                  VARCHAR2,
                      C1_REMOVEFNFDATA_cv IN OUT cv_types.customer_tp) IS
  
     l_count NUMBER := 0;
   d_DestNumber1 PRODUCT_EXT_DATA.param_value%TYPE;
   d_DestNumber2 PRODUCT_EXT_DATA.param_value%TYPE;
    d_DestNumber3 PRODUCT_EXT_DATA.param_value%TYPE;
   d_DestNumber4 PRODUCT_EXT_DATA.param_value%TYPE;
   d_DestNumber5 PRODUCT_EXT_DATA.param_value%TYPE;
   d_DestNumber6 PRODUCT_EXT_DATA.param_value%TYPE;
   d_DestNumber7 PRODUCT_EXT_DATA.param_value%TYPE;
   d_DestNumber8 PRODUCT_EXT_DATA.param_value%TYPE;
   d_DestNumber9 PRODUCT_EXT_DATA.param_value%TYPE;
  d_DestNumber10 PRODUCT_EXT_DATA.param_value%TYPE;
  
      CURSOR c_dest_num IS
     SELECT P.VIEW_ID as view_id, P.param_value as destination_number
      FROM ORD_ITEM o, 
       PRODUCT_EXT_DATA p
      WHERE o.service_order_id = to_number(v_soid)
    AND O.ITEM_ACTION_ID IN (30) -- delete
    AND P.VIEW_ID          = O.VIEW_ID
    AND P.PARAM_ID         = 5100
    AND o.is_cancelled     = 0;
    d_dest_num c_dest_num%rowtype;
  
    BEGIN
     SELECT count(*) 
    INTO l_count
      FROM ORD_ITEM o, 
       PRODUCT_EXT_DATA p
    WHERE o.service_order_id = to_number(v_soid)
   AND o.member_type      = 10   -- product
   AND O.ITEM_ACTION_ID IN (30) -- delete
   AND P.VIEW_ID          = O.VIEW_ID
   AND P.PARAM_ID         = 5100
   AND o.is_cancelled     = 0;
  
      IF(l_count != 0) THEN
  
       OPEN c_dest_num;
     LOOP FETCH c_dest_num INTO d_dest_num;
     EXIT WHEN c_dest_num%NOTFOUND;
  
      for i in 1 .. l_count
     LOOP
     d_DestNumber+i := d_dest_num.destination_number;
  
     END LOOP;
     END LOOP;
     CLOSE c_dest_num;
     END IF;
  
  
  
    OPEN C1_REMOVEFNFDATA_CV FOR 
     SELECT l_count AS FnfRemoveCompCount,
      d_DestNumber1 AS DestNumber1,
      d_DestNumber2 AS DestNumber2,
      d_DestNumber3 AS DestNumber3,
      d_DestNumber4 AS DestNumber4,
      d_DestNumber5 AS DestNumber5,
      d_DestNumber6 AS DestNumber6,
      d_DestNumber7 AS DestNumber7,
      d_DestNumber8 AS DestNumber8,
      d_DestNumber9 AS DestNumber9,
      d_DestNumber10 AS DestNumber10,
      FROM DUAL;
  
     END;
  </code></pre>