title: Getting a PL/SQL Cursor for loop to work with input variable?
body: <p>I have to produce PL/SQL block that takes the input in of an integer where n (1 ≤ n ≤ 100) and display the most popular names for male and female.  If the number entered is out of that range display an invalid input. I have created a table called popular names that has 100 of the most popular names for male and female.  I am struggling with my FOR loop and getting it to work with the user input.  My code is below:</p>
  
  <pre><code>ACCEPT p_1 prompt 'please enter an integer between 1 and 100'
  
  DECLARE
      CURSOR name_cur IS
              SELECT    rank, male_given_name, female_given_name
              FROM          popular_names
            ORDER BY  rank;
  
          v_nrank         popular_names.rank%TYPE := &amp;p_1;
          v_nmale           popular_names.male_given_name%TYPE;
          v_nfemale     popular_names.female_given_name%TYPE;
  
  
  
  BEGIN   
        OPEN name_cur;
        FETCH name_cur INTO v_nrank, v_nmale, v_nfemale;
  
        IF name_cur%FOUND THEN
          DBMS_OUTPUT.PUT_LINE('Rank     Male Given Name     Female Given Name');
          DBMS_OUTPUT.PUT_LINE('----------------------------------------------');
  
  
          FOR i IN 1..v_nrank LOOP
              DBMS_OUTPUT.PUT_LINE((RPAD(v_nrank, 18) || '  ' || 
                  (RPAD(v_nmale, 18) || '  ' || v_nfemale)));
                  FETCH name_cur INTO v_nrank, v_nmale, v_nfemale; 
                EXIT WHEN name_cur%NOTFOUND;
          END LOOP;
  
  
        ELSE
            DBMS_OUTPUT.PUT_LINE('Invalid number!');
        END IF;
  
          CLOSE name_cur;
  END;
  </code></pre>