-- Connect programmer/p@9i

set serveroutput on

Drop function Get_Grade3;

create or replace function Get_Grade3(score IN NUMBER) RETURN VARCHAR2 is

begin
  -- use a Searched CASE Statement to find the Grade for the 
  -- score passed in as a parameter
  CASE 
    WHEN score BETWEEN 80 AND 100 THEN return 'A';
    WHEN score BETWEEN 65 AND 79  THEN return 'B';

    WHEN score BETWEEN 50 AND 64  THEN return 'C';
    WHEN score BETWEEN 40 AND 49  THEN return 'D';
    WHEN score BETWEEN 0  AND 39  THEN return 'F';
    --Comment the ELSE leg to generate the exception
    --ELSE return 'Invalid score';
  END CASE;
exception

  when CASE_NOT_FOUND then
    return 'Exception - Case Not Found for score - '|| score;
end Get_Grade3;
/
Show Errors

select Get_Grade3(-1) from dual
/