title: Invalid SQL statement error with refcursor
body: <p>I am trying to get the results of the underlying statements. The SQL statements works without any problems. However, in order to print the results I would like to use refcursor. I get the following errors:</p>
  
  <p>ORA-00900: invalid SQL statement
  ORA-01008: not all variables bound
  ORA-00900: invalid SQL statement</p>
  
  <pre><code>VARIABLE reader refcursor;
  DECLARE
    line varchar2(32767);
  BEGIN
    line := 'SELECT role_id,';
    FOR n IN (SELECT name
                FROM (SELECT competence.skill_role.role_id,
                             competence.skill_label.name,
                             competence.skill_role.target_value
                        FROM competence.skill_role,
                             competence.skill_label
                       WHERE competence.skill_label.skill_id =
                             competence.skill_role.skill_id
                         AND competence.skill_label.language_id = 1)
                         matrix_result ) LOOP
      line := line || '(decode(name,''' || n.name ||
              ''',target_value)) "' || n.name || '",';
    END LOOP;
    line := RTRIM(line, ',') ||
      ' FROM (SELECT competence.skill_role.role_id,
                     competence.skill_label.name,
                     competence.skill_role.target_value
                FROM competence.skill_role, competence.skill_label
               WHERE competence.skill_label.skill_id =
                     competence.skill_role.skill_id
                 AND competence.skill_label.language_id = 1) matrix_result';
  --dbms_output.put_line(line);
  --execute immediate line;
   OPEN :reader FOR line;
  END;
  /
  PRINT :reader;
  </code></pre>
  
  <p>Table data </p>
  
  <pre><code>CREATE TABLE competence.skill_role
    (skill_id  NUMBER,
     role_id NUMBER,
     target_value NUMBER)
  /
  INSERT ALL 
  INTO competence.skill_role VALUES (3432030, 1421866, 2)
  INTO competence.skill_role VALUES (3434962, 1421866, 2)
  INTO competence.skill_role VALUES (3488025, 3488804, 4)
  
  
  SELECT * FROM competence.skill_role
  
  SKILL_ID ROLE_ID     target_value
  ---------- -------   -----------
  3432030 1421866       2
  3434962 1421866       2
  3488025 3488804       4
  
  
  CREATE TABLE competence.skill_label
    (skill_id  NUMBER,
     name vchar2 (30))
  /
  INSERT ALL 
  INTO competence.skill_label VALUES (3432030, 'Alueen projektipätevyys')
  INTO competence.skill_label VALUES (3434962, 'Moottorin koekäyttö')
  INTO competence.skill_label VALUES (3488025, 'Etähallintajärjestelmät')
  
  
  SELECT * FROM arc_competence.skill_label
  
  SKILL_ID NAME
  ---------- -------
  3432030, Alueen projektipätevyys
  3434962, Moottorin koekäyttö
  3488025, Etähallintajärjestelmät
  </code></pre>
  
  <p>I would like to have the following result from the first query. From your answer (if I understood correctly), it seems that I need to run the resultant query manually to get the answer. I'd like to have the result without running the resultant query :-) I don't have the access to the client machine at the moment but I am going there now.</p>
  
  <pre><code>ROLE_ID     Alueen projektipätevyys  Moottorin koekäyttö    Etähallintajärjestelmät          
  1421866          2                      2
  3488804                                                            4       
  </code></pre>