Other Suggestions
The following example shows the aforementioned suggestions. Notice that it also uses a
REM ********************************************************
REM * filename: coursediscount01.sql version: 1
REM * purpose: To give discounts to courses that have at
REM * least one section with an enrollment of more
REM * than 10 students.
REM * args: none
REM *
REM * created by: s.tashi date: January 1, 2000
REM * modified by: y.sonam date: February 1, 2000
REM * description: Fixed cursor, added indentation and
REM * comments.
REM ********************************************************
DECLARE
-- C_DISCOUNT_COURSE finds a list of courses that have
-- at least one section with an enrollment of at least 10
-- students.
CURSOR c_discount_course IS
SELECT DISTINCT course_no
FROM section sect
WHERE 10 <= (SELECT COUNT(*)
FROM enrollment enr
WHERE enr.section_id = sect.section_id
);
-- discount rate for courses that cost more than 00.00
con_discount_2000 CONSTANT NUMBER := .90;
-- discount rate for courses that cost between 01.00
-- and 00.00
con_discount_other CONSTANT NUMBER := .95;
v_current_course_cost course.cost%TYPE;
v_discount_all NUMBER;
e_update_is_problematic EXCEPTION;
BEGIN
-- For courses to be discounted, determine the current
-- and new cost values
FOR r_discount_course in c_discount_course LOOP
SELECT cost
INTO v_current_course_cost
FROM course
WHERE course_no = r_discount_course.course_no;
IF v_current_course_cost > 2000 THEN
v_discount_all := con_discount_2000;
ELSE
IF v_current_course_cost > 1000 THEN
v_discount_all := con_discount_other;
ELSE
v_discount_all := 1;
END IF;
END IF;
BEGIN
UPDATE course
SET cost = cost * v_discount_all
WHERE course_no = r_discount_course.course_no;
EXCEPTION
WHEN OTHERS THEN
RAISE e_update_is_problematic;
END; -- end of sub-block to update record
END LOOP; -- end of main LOOP
COMMIT;
EXCEPTION
WHEN e_update_is_problematic THEN
-- Undo all transactions in this run of the program
ROLLBACK;
DBMS_OUTPUT.PUT_LINE
('There was a problem updating a course cost.');
WHEN OTHERS THEN
NULL;
END;
/
|
Appendix C. Student Database Schema
Table and Column Descriptions |
Table and Column DescriptionsCOURSE: Information for a course
SECTION: Information for an individual section (class) of a particular course
STUDENT: Profile information for a student
ENROLLMENT: Information for a student registered for a particular section of a particular course (class)
INSTRUCTOR: Profile information for an instructor
ZIPCODE: City, state, and zipcode information
GRADE_TYPE: Lookup table of a grade type (code) and its description
GRADE_TYPE_WEIGHT: Information on how the final grade for a particular section is computed; for example, the midterm
|
|
Column Name |
Null |
Type |
Comments |
|---|---|---|---|
|
SECTION_ID |
NOT NULL |
NUMBER(8) |
The ID for a section |
|
GRADE_TYPE_CODE |
NOT NULL |
CHAR(2) |
The code which identifies a category of grade |
|
NUMBER_PER_SECTION |
NOT NULL |
NUMBER(3) |
How many of these grade types can be used in this section (i.e., there may be three quizzes) |
|
PERCENT_OF_FINAL_GRADE |
NOT NULL |
NUMBER(3) |
The percentage this category of grade
|
|
DROP_LOWEST |
NOT NULL |
CHAR(1) |
Is the
|
|
CREATED_BY |
NOT NULL |
VARCHAR2(30) |
Audit column ” indicates user who inserted data |
|
CREATED_DATE |
NOT NULL |
DATE |
Audit column ” indicates date of insert |
|
MODIFIED_BY |
NOT NULL |
VARCHAR2(30) |
Audit column ” indicates who made last update |
|
MODIFIED_DATE |
NOT NULL |
DATE |
Audit column ” date of last update |
|
Column Name |
Null |
Type |
Comments |
|---|---|---|---|
|
STUDENT_ID |
NOT NULL |
NUMBER(8) |
The ID for a student |
|
SECTION_ID |
NOT NULL |
NUMBER(8) |
The ID for a section |
|
GRADE_TYPE_CODE |
NOT NULL |
CHAR(2) |
The code that identifies a category of grade |
|
GRADE_CODE_OCCURRENCE |
NOT NULL |
NUMBER(38) |
The sequence number of one grade type for one section. For example, there could be multiple assignments numbered 1, 2, 3, etc. |
|
NUMERIC_GRADE |
NOT NULL |
NUMBER(3) |
Numeric grade value (e.g., 70, 75) |
|
COMMENTS |
NULL |
VARCHAR2(2000) |
Instructor's comments on this grade |
|
CREATED_BY |
NOT NULL |
VARCHAR2(30) |
Audit column ” indicates user who inserted data |
|
CREATED_DATE |
NOT NULL |
DATE |
Audit column ” indicates date of insert |
|
MODIFIED_BY |
NOT NULL |
VARCHAR2(30) |
Audit column ” indicates who made last update |
|
MODIFIED_DATE |
NOT NULL |
DATE |
Audit column ” date of last update |
|
Column Name |
Null |
Type |
Comments |
|---|---|---|---|
|
LETTER_GRADE |
NOT NULL |
VARCHAR(2) |
The unique grade as a letter (A, A-, B, B+, etc.) |
|
GRADE_POINT |
NOT NULL |
NUMBER(3,2) |
The number grade on a scale from 0 (F) to 4 (A) |
|
MAX_GRADE |
NOT NULL |
NUMBER(3) |
The highest grade number that corresponds to this letter grade |
|
MIN_GRADE |
NOT NULL |
NUMBER(3) |
The lowest grade number that corresponds to this letter grade |
|
CREATED_BY |
NOT NULL |
VARCHAR2(30) |
Audit column ” indicates user who inserted data |
|
CREATED_DATE |
NOT NULL |
DATE |
Audit column ” indicates date of insert |
|
MODIFIED_BY |
NOT NULL |
VARCHAR2(30) |
Audit column ” indicates who last made update |
|
MODIFIED_DATE |
NOT NULL |
DATE |
Audit column ” date of last update |