Hi folks
I'm using 11g Express Edition 11.2.0.2.0.
The code below runs fine. It takes a parameter (student_id in this instance), and returns some test data including 'pass' or 'fail' etc.
At the moment i'm struggling with creating some exceptions that will handle things such as the parameter not being an integer, the parameter being null etc.
Replicating these errors returns the error code ORA-06550, which i understand from researching this forum, cant be handled as its a compilation time error and not an execution time error.
Is it possible to alter my code somehow, so that i can still get the same outcome, but also write some exceptions based on the parameter input.
Any help is much appreciated.
Thanks
Ben
SET SERVEROUTPUT ON
DECLARE
CURSOR c_pass_fail_cursor
(p_studentid number) IS
SELECT STUDENTS.FIRSTNAME,
TEST_HISTORY.SCORE,
TEST_ID.TEST_NAME,
TEST_ID.PASSING_GRADE
FROM STUDENTS
INNER JOIN TEST_HISTORY
ON STUDENTS.STUDENT_ID = TEST_HISTORY.STUDENT_ID
INNER JOIN TEST_ID
ON TEST_ID.TEST_ID = TEST_HISTORY.TEST_ID
WHERE students.STUDENT_ID = p_studentid;
v_name students.firstname%type;
v_score test_history.score%type;
v_test test_id.test_name%type;
v_passing test_id.passing_grade%type;
v_result varchar2(4);
BEGIN
OPEN c_pass_fail_cursor (3);
LOOP
FETCH c_pass_fail_cursor INTO v_name, v_score, v_test, v_passing;
EXIT WHEN c_pass_fail_cursor%NOTFOUND;
If v_score < v_passing THEN
v_result := 'Fail';
DBMS_OUTPUT.PUT_LINE(v_name || ' ' || v_score || ' ' || v_test || ' ' || V_passing || ' ' || 'Result =' || v_result);
ELSE
v_result := 'Pass';
DBMS_OUTPUT.PUT_LINE(v_name || ' ' || v_score || ' ' || v_test || ' ' || V_passing || ' ' || 'Result =' || v_result);
END IF;
END LOOP;
CLOSE c_pass_fail_cursor;
END;
/