PDA

View Full Version : Why doesnt the else statement work in this?




bigMAC28
Aug 4, 2013, 03:05 PM
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'



lee1210
Aug 4, 2013, 04:04 PM
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

bigMAC28
Aug 4, 2013, 04:44 PM
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

Hahaha I cant believe i missed that! Thanks!