Why doesnt the else statement work in this?

Discussion in 'Mac Programming' started by bigMAC28, Aug 4, 2013.

  1. macrumors member

    Joined:
    Apr 16, 2012
    Location:
    Chicago
    #1
    Code:
    ACCEPT p_1 PROMPT 'Please enter an Interger between 1 and 100:'
    
    DECLARE
      v_rank number;
    	v_input	Popular_names.rank%TYPE := '&p_1';
      v_mname varchar2(20);
      v_fname varchar2(20);	
    BEGIN
      SELECT rank
      INTO v_rank
      FROM Popular_names
    	WHERE rank=v_input;
      IF v_input>= 1 and v_input<= 100 THEN
          DBMS_OUTPUT.PUT_LINE('Valid!');
      ELSE
        DBMS_OUTPUT.PUT_LINE('Invalid Number!');
    END IF;
    END;

    The IF Statement works fine but i get a 01403. 00000 - "no data found" error when i enter '101'
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    Your conditional is after you do a select with an invalid value. Put your select inside the if or catch the error and handle it instead.

    -Lee
     
  3. thread starter macrumors member

    Joined:
    Apr 16, 2012
    Location:
    Chicago
    #3
    Hahaha I cant believe i missed that! Thanks!
     

Share This Page