I created this procedure to validate a login. The DBMS OUTPUT in the first IF statement outputs fine, but the DBMS OUTPUT in the ELSE statement doesn't display anything when I enter invalid info; I'm not sure why?
CREATE OR REPLACE PROCEDURE member_ck_sp
(p_username IN VARCHAR2,
p_password IN VARCHAR2)
IS
p_check VARCHAR2(10):= 'INVALID';
fullname VARCHAR2(20);
CURSOR member_cur IS
SELECT username, firstname, lastname, cookie, password
FROM bb_shopper
WHERE username = p_username
AND password = p_password;
BEGIN
FOR rec_cur IN member_cur LOOP
IF p_username = rec_cur.username AND p_password = rec_cur.password THEN
fullname := rec_cur.firstname || ' ' || rec_cur.lastname;
DBMS_OUTPUT.PUT_LINE('Name: ' || fullname || ' Cookie: ' || rec_cur.cookie);
DBMS_OUTPUT.PUT_LINE('LOGGED IN');
ELSE
DBMS_OUTPUT.PUT_LINE('INVALID');
END IF;
END LOOP;
END member_ck_sp;
BEGIN
member_ck_sp('rat55', 'kile');
END;
p_username = rec_cur.username AND p_password = rec_cur.passwordis always true. The cursor is only selecting rows from the table where the username and password match. YourIFstatement then makes another check that they match (which will always be true), hence theELSEblock will never be executed.