Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2011
    Posts
    9

    Unanswered: Problem with a login function

    I am trying to make an login function that are going to return two different message. One of them is that the login in was Successful and the other that it was failed. The function are going to compare the input that functions get with another table(BANKKUND), and see if it matches.
    My problem is that the function dont return the right message.
    Here is my code:

    CREATE OR REPLACE FUNCTION logga_in (v_pnr in bankkund.pnr%TYPE, v_passwd in bankkund.passwd%TYPE)
    RETURN VARCHAR2 AS
    v_result VARCHAR2(50);
    CURSOR c_passwd IS SELECT bankkund.pnr, bankkund.passwd
    FROM BANKKUND
    WHERE bankkund.pnr = V_PNR
    AND bankkund.passwd = V_PASSWD
    GROUP BY bankkund.pnr, bankkund.passwd;
    v_lpnr bankkund.pnr%TYPE;
    v_lpasswd bankkund.passwd%TYPE;
    BEGIN
    IF NOT c_passwd%isopen then
    OPEN c_passwd;
    END IF;
    LOOP
    FETCH c_passwd
    INTO v_lpnr, v_lpasswd;
    EXIT WHEN c_passwd%notfound;
    IF v_pnr in (V_LPNR)
    AND V_PASSWD in(v_lpasswd)
    THEN
    v_result := 'Login failed!';
    RETURN v_result;
    ELSE
    v_result := 'Login success!';
    RETURN v_result;
    end if;
    end LOOP;
    close c_passwd;
    end;
    /
    The return message with this code is "LOGGA_IN('433','GRGR')" And thats the function name with my test values.
    Do anyone have some suggestion hove I can solve my problem?

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Please realize that we don't have your tables & we don't have your data.
    Therefore we can't run, test or improve your posted SQL.

    I think I see a problem in posted code.
    Code RETURN after first record read ALWAYS! & never check subsequent records
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Feb 2011
    Posts
    9
    Thanks for the tip, now its working!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •