Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Function created with compile errors

tina75tina75 Member Posts: 8
[b][blue]My function is supposed to return a grade for a score passed to it as a parameter. When I run the script the message given is:
[red]Warning: Function created with compilation error.[/red]

Where's my error?[/b][/blue]
[code]CREATE OR REPLACE FUNCTION convert_grade
(v_score grade.numeric_grade%TYPE)
RETURN varchar2
AS
v_letter_grade varchar2(20);
BEGIN
IF v_score BETWEEN 90 AND 100 THEN
v_letter_grade := 'A';
ELSEIF v_score BETWEEN 80 AND 89 THEN
v_letter_grade := 'B';
ELSEIF v_score BETWEEN 70 AND 79 THEN
v_letter_grade := 'C';
ELSEIF v_score BETWEEN 60 AND 69 THEN
v_letter_grade := 'D';
ELSE
v_letter_grade := 'F';
END IF;
RETURN v_letter_grade;
EXCEPTION
WHEN NO_DATA_FOUND THEN
v_letter_grade := 'Grade not found';
RETURN v_letter_grade;
WHEN OTHERS THEN
v_letter_grade := 'Error in the function.';
RETURN v_letter_grade;
END;
/
[/code]

Comments

  • infidelinfidel Member Posts: 2,900
    : [b][blue]My function is supposed to return a grade for a score passed to it as a parameter. When I run the script the message given is:
    : [red]Warning: Function created with compilation error.[/red]
    :
    : Where's my error?[/b][/blue]
    : [code]CREATE OR REPLACE FUNCTION convert_grade
    : (v_score grade.numeric_grade%TYPE)
    : RETURN varchar2
    : AS
    : v_letter_grade varchar2(20);
    : BEGIN
    : IF v_score BETWEEN 90 AND 100 THEN
    : v_letter_grade := 'A';
    : [red]ELSEIF[/red] v_score BETWEEN 80 AND 89 THEN
    : v_letter_grade := 'B';
    : [red]ELSEIF[/red] v_score BETWEEN 70 AND 79 THEN
    : v_letter_grade := 'C';
    : [red]ELSEIF[/red] v_score BETWEEN 60 AND 69 THEN
    : v_letter_grade := 'D';
    : ELSE
    : v_letter_grade := 'F';
    : END IF;
    : RETURN v_letter_grade;
    : EXCEPTION
    : WHEN NO_DATA_FOUND THEN
    : v_letter_grade := 'Grade not found';
    : RETURN v_letter_grade;
    : WHEN OTHERS THEN
    : v_letter_grade := 'Error in the function.';
    : RETURN v_letter_grade;
    : END;
    : /
    : [/code]

    The keyword in oracle is "elsif", not "elseif". I actually read in a book somewhere that the compiler "gets confused" if it sees "elseif" because it thinks you meant "else if". Stupid.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

Sign In or Register to comment.